Skip to content

How do I install SSM Agent on an Amazon EC2 Linux instance at launch?

3 minute read
2

I want to install the AWS Systems Manager Agent (SSM Agent) on my Amazon Elastic Compute Cloud (Amazon EC2) Linux instance. I want the agent to start before launch.

Resolution

For a list of Amazon Machine Images (AMIs) with the SSM Agent preinstalled, see Find AMIs with the SSM Agent preinstalled. You must manually install the SSM Agent on EC2 instances that you create from other versions of Linux AMIs.

Prerequisites: Before you install the SSM Agent, verify that you use a supported operating system (OS). Also, complete the prerequisites for Session Manager, a capability of AWS Systems Manager.

To install SSM Agent at launch, complete the following steps to add user data to the instance before you launch the instance:

  1. Create an AWS Identity and Access Management (IAM) instance profile to use with SSM Agent.

  2. Launch a new instance, and then configure your instance settings, such as application and OS images, instance type, key pair, network settings, and storage.

  3. Expand the Advanced details section, and then select your IAM instance profile from the IAM instance profile dropdown list.

  4. For User data, enter the following code based on your OS.
    Amazon Linux 2 (AL2), Red Hat Enterprise Linux (RHEL) 7, and CentOS 7 (64 bit) x86_64 instances:

    #!/bin/bash
    cd /tmp
    sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
    sudo systemctl enable amazon-ssm-agent
    sudo systemctl start amazon-ssm-agent

    AL2, RHEL 7, and CentOS 7 (64 bit) ARM64 instances:

    #!/bin/bash
    cd /tmp
    sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_arm64/amazon-ssm-agent.rpm
    sudo systemctl enable amazon-ssm-agent
    sudo systemctl start amazon-ssm-agent

    Amazon Linux 2023 (AL2023), RHEL 8, 9 and 10, and CentOS 8 and 9 (64 bit) x86_64 instances:

    #!/bin/bash
    cd /tmp
    sudo dnf install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
    sudo systemctl enable amazon-ssm-agent
    sudo systemctl start amazon-ssm-agent

    AL2023, RHEL 8, 9 and 10 and CentOS 8 and 9 (64 bit) ARM64 instances:

    #!/bin/bash
    cd /tmp
    sudo dnf install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_arm64/amazon-ssm-agent.rpm
    sudo systemctl enable amazon-ssm-agent
    sudo systemctl start amazon-ssm-agent

    Note: You must install Python 2 or Python 3 on your RHEL 9, RHEL 8, or CentOS 8 instance to use the SSM Agent. To install Python, add the following command after #!/bin/bash in the preceding code examples:

    sudo dnf install python3

    Ubuntu 22 and Ubuntu 16 (Deb installer), Debian 8, and Debian 9:

    #!/bin/bash
    mkdir /tmp/ssm
    cd /tmp/ssm
    wget https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb
    sudo dpkg -i amazon-ssm-agent.deb
    sudo systemctl start amazon-ssm-agent

    Ubuntu 14 (Deb installer):

    #!/bin/bash
    mkdir /tmp/ssm
    cd /tmp/ssm
    wget https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb
    sudo dpkg -i amazon-ssm-agent.deb
    sudo start amazon-ssm-agent

    SUSE 15 and SUSE 12:

    #!/bin/bash
    mkdir /tmp/ssm
    cd /tmp/ssm
    wget https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
    sudo rpm --install amazon-ssm-agent.rpm
    sudo systemctl enable amazon-ssm-agent
    sudo systemctl start amazon-ssm-agent
  5. For more information about user data, see User data in the AWS Management Console.

  6. Under Summary, enter the number of instances that you want to launch.

  7. Choose Launch instance.

  8. (Optional) To automatically update the SSM Agent, configure Auto update SSM Agent.

Related information

Working with SSM Agent on EC2 instances for Linux

Working with SSM Agent on EC2 instances for Windows Server

How do I install SSM Agent on an Amazon EC2 Windows instance at launch?

Why isn't AWS Systems Manager showing my Amazon EC2 instance as a managed instance?

AWS OFFICIALUpdated 4 months ago
6 Comments

If executing the userdata after the initial launch, add the below before your #!/bin/bash :

Content-Type: multipart/mixed; boundary="//" MIME-Version: 1.0

--// Content-Type: text/cloud-config; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="cloud-config.txt"

#cloud-config cloud_final_modules:

  • [scripts-user, always]

--// Content-Type: text/x-shellscript; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="userdata.txt"

replied 3 years ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

AWS
EXPERT

replied 3 years ago

When using Graviton hosts, in step 4 replace _amd64 with _arm64 in the .deb or .rpm download URL.

E.g. for RHEL9 you must use:

sudo dnf install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_arm64/amazon-ssm-agent.rpm
AWS

replied 3 years ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

AWS
EXPERT

replied 3 years ago

Since Red Hat Enterprise Linux (RHEL) 7, and CentOS 7 (64 bit) does not use DNF by default unless installed, you can have them under yum section.

AWS

replied a year ago

This article was reviewed and updated on 2026-04-28

AWS
EXPERT

replied 4 months ago