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:
- Create an AWS Identity and Access Management (IAM) instance profile to use with SSM Agent.
- Launch a new instance, and then configure your instance parameters, such as application and OS images, instance type, key pair, network settings, and storage.
- Expand the Advanced details section, and then select your IAM instance profile from the IAM instance profile dropdown list.
- 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.
- Under Summary, enter the number of instances that you want to launch.
- Choose Launch instance.
- (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?