Skip to content

Connect to your instance

You need a terminal on the instance to reset or turn off the password, read the service logs, or work in Python directly. There are three ways in.

In the browser, with no key pair and no local software. Select the instance in the EC2 console and choose Connect. On the EC2 Instance Connect tab, check that Username is ubuntu, then choose Connect.

This needs port 22 open to AWS's own Instance Connect addresses, because the connection comes from AWS rather than from your computer. The seller settings security group allows this.

The instance also needs a public IP address, and your AWS user needs permission to use EC2 Instance Connect.

If you have restricted port 22 to your own IP, the browser connection will fail. Add an inbound rule for port 22 whose source is the managed prefix list com.amazonaws.<region>.ec2-instance-connect, for example com.amazonaws.us-east-1.ec2-instance-connect.

If you chose a key pair at launch:

ssh -i <key>.pem ubuntu@<public-ip>

The user name is always ubuntu. This is also the way to copy files to and from the instance with scp.

No key pair? EC2 Instance Connect can also send a temporary key for your own SSH client, with aws ec2-instance-connect send-ssh-public-key, valid for 60 seconds. See AWS's Instance Connect guide.

No open ports at all, and access is controlled entirely by IAM. Give the instance an IAM role with the AmazonSSMManagedInstanceCore policy (in the EC2 console: Actions, Security, Modify IAM role), wait a few minutes, then choose Connect and the Session Manager tab.

Session Manager signs you in as ssm-user, not ubuntu. Run this first to get the same environment as SSH, with the Python environment active:

sudo -iu ubuntu