Each AMI publisher on EC2 decides what user (or users) should have ssh access enabled by default and what ssh credentials should allow you to gain access as that user.
For the second part, most AMIs allow you to ssh in to the system with the ssh keypair you specified at launch time. This is so common, users often assume that it is built in to EC2 even though it must be enabled by each AMI provider.
Unfortunately, there is no standard ssh username that is used to access EC2 instances across operating systems, distros, and AMI providers.
Here are some of the ssh usernames that I am aware of at this time:
|Legacy / Community / Other AMI
|RHEL 6.4 and later||
|RHEL 6.3 and earlier||root|
Even though the above list will get you in to most official AMIs, there may still be situations where you aren’t quite sure how the AMI was built or what user should be used for ssh.
If you know you have the correct ssh key but don’t know the username, this code can be used to try a number of possibilities, showing which one(s) worked:
host=<IP_ADDRESS> keyfile=<SSH_KEY_FILE.pem> for user in root ec2-user ubuntu admin bitnami do if timeout 5 ssh -i $keyfile $user@$host true 2>/dev/null; then echo "ssh -i $keyfile $user@$host" fi done
Some AMIs are configured so that an ssh to
root@ will output a message informing you the correct user to use and then close the connection. For example,
$ ssh root@<UBUNTUHOST> Please login as the user "ubuntu" rather than the user "root".
When you ssh to a username other than
root, the provided user generally has passwordless
sudo access to run commands as the
root user. You can use
rsync with EC2 hosts in this configuration.
If you know of other common ssh usernames from popular AMI publishers, please add notes in the comments with a link to the appropriate documentation.