Default ssh Usernames For Connecting To EC2 Instances
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:
OS/DistroOfficial AMI
ssh UsernameLegacy / Community / Other AMI
ssh Usernames Amazon Linuxec2-user
Ubuntuubunturoot
Debianadminroot
RHEL 6.4 and laterec2-user
RHEL 6.3 and earlierroot
Fedoraec2-userroot
Centoscentosroot
SUSEroot
BitNamibitnami
TurnKeyroot
NanoStackubuntu
FreeBSDec2-user
OmniOSroot
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 ec2-user ubuntu centos admin bitnami root
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 sudo
, ssh
, and 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.
[Update 2015-12-04: CentOS 7 now uses ssh to the centos
user instead of root
. Thanks to Cloudist for posting in the comments.]
Hope this will help you!
Please Remember me in your prayers!
Enjoy
