SCP and SSH Solution on Amazon EC2 Linux AMI

Written by

A while back I setup a new Amazon EC2 micro-instance using Amazon’s own Linux AMI (based on Centos). On firing up the instance I attempted to run a simple scp command which ultimately failed. The reason I wanted to use the scp command was to push and append to authorized_keys my own generated SSH key to my instance, this is a personal preference over the generated Key Pair (.pem) Amazon recommends you use.

As you may be aware, this particular setup also discourages (and as I recall prevents) a root password login, naturally for heightened security, so I had to do some digging. I soon discovered that using the cat command I could work around the issue and append my local public ssh key to the authorized_keys on the remote server. This is what it should look like:

1
cat ~/.ssh/id_dsa.pub | ssh -i your-amazon-generated-key.pem ec2-user@your-amazon-instance-ip "cat>> .ssh/authorized_keys"

You should then be able to SSH into your server using RSA based authentication and ultimately regain the privilege to use the scp command.

Funnily enough @vandergoog pointed out on Twitter a similar person undergoing the same issue whom also resolved it in the same manner, plus a poll was setup and there are a few votes for true, so I am not alone on this.

Please note that I am sure that this is due to some inherent Amazon/security logic that is both recommended plus beneficial and I am missing the boat on this one, any further insight from any hardcore Linux/SSH users would be appreciated.

Comments