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

3 minute read
1

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

Resolution

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

Prerequisites: Before you install SSM Agent, you must use a supported operating system (OS) and complete the SSM Agent prerequisites.

To install SSM Agent, add user data to an Amazon EC2 Linux instance before you launch the instance.

Complete the following steps:

  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 parameters, 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 information for your OS.
    Amazon Linux 2023, Amazon Linux 2, Red Hat Enterprise Linux (RHEL) 7, and CentOS 7 (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
    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 for SSM Agent to work correctly. To install Python, add the following command after #!/bin/bash to the preceding x86_64 and ARM64 command examples:
    sudo dnf install python3
    Amazon Linux and CentOS 6 (64 bit):
    #!/bin/bash
    cd /tmp
    sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
    sudo start amazon-ssm-agent
    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
    For more information about user data, see User data in the AWS Management Console.
  5. Under Summary, enter the number of instances that you want to launch.
  6. Choose Launch instance.
  7. (Optional) To automatically update SSM Agent, choose Auto update SSM Agent.

For Windows, see How do I install AWS Systems Manager Agent (SSM Agent) on an Amazon EC2 Windows instance at launch?

Related information

Automating updates to SSM Agent

Working with SSM Agent on EC2 instances for Linux

Working with SSM Agent on EC2 instances for Windows Server

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

AWS OFFICIAL
AWS OFFICIALUpdated a month ago
4 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 2 years ago

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

profile pictureAWS
EXPERT
replied 2 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 a year ago

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

profile pictureAWS
EXPERT
replied a year ago