How do I set up SSH access for an Amazon EC2 instance?

STEP 1) Download private keys assigned to your ec2 machine (which is only one time download when created. so recommended to commit somewhere)

STEP 2) and fire following commands,

chmod 400 MyKeyPair.pem
ssh -i MyKeyPair.pem [email protected]

Official Doc : Connecting to Your Linux/Unix Instances Using SSH


ssh -i /path/to/private-key ubuntu@<ec2-public-dns-address>

just use ubuntu instead of root. Your problem will be solved. Cheers!


Basically, you need a private-key file to login into your EC2 via SSH. Follow these steps to create one:

  • Go https://console.aws.amazon.com/ec2/home & sign in to your existing Amazon account.
  • Click on "Key Pairs" on LHS or https://console.aws.amazon.com/ec2/home?region=us-east-1#s=KeyPairs.
    • You should see the list of KEYs generated by you (or during EC2 creation process).
    • Click on "Create Key Pair" if you don't see any or you lost your private-key.
    • Enter a unique name and hit enter.
    • A download panel will appear for you to save the private-key, save it.
    • Keep it somewhere with the file permission "0600"
  • Click on "Instances" on LHS or https://console.aws.amazon.com/ec2/home?region=us-east-1#s=Instances
    • You should see the list of ec2-instances, if you don't see any, then please create one.
    • Click on the EC2 machine and note down the Public DNS address.
  • Open your Terminal (in Linux) and type the following command
    • ssh -i /path/to/private-key root@<ec2-public-dns-address> - the root username has been avoided in the latest releases, based on your distribution select ec2-user or ubuntu as your username.
    • hit Enter
    • That's it.