how to SSH to EC2 without explicitly using the pem key?

I have a windows as my main OS. Using VMware player, I setup a Ubuntu server 12.4 as a guest machine. The Ubuntu server have "ubuntu" user.

I created a new EC2 instance + setup pem key. From the windows machine, when I use putty+pem key - I can ssh.

I added the pem key to my VMware Ubuntu server ( /home/ubuntu/.ssh/) In addition, i set the following permissions: chmod 700 /home/ubuntu/.ssh chmod 600 /home/ubuntu/.ssh/*

Through the Ubuntu server - I tried to SSH to the ec2 instance without success: ssh ubuntu@EC2_IP Permission denied (publickey) . If I explicit use the pem key, it works: ssh -i /home/ubuntu/.ssh/NAME.pem ubuntu@EC2_IP - Please note, that I must use direct path to the key, otherwise, I'll get Warning: Identity file NAME.pem not accessible: No such file or directory. Permission denied (publickey).

Please advise. Thanks!


Solution 1:

Add EC2 pem key to SSH

ssh-add ~/.ssh/KEY_PAIR_NAME.pem

Solution 2:

By default the SSH client will look for keys named id_rsa, id_dsa and id_ecdsa in ~/.ssh/. If your key isn't named like that you either need to specify it on the command line with -i as you've been doing, or specify it in the client configuration.

You can add something like this to ~/.ssh/config to automatically select this key when SSHing to EC2:

Host *.compute-1.amazonaws.com
    IdentityFile ~/.ssh/ec2_rsa