Ssh – EC2: how to download the private key file for a user

amazon ec2sshssh-keygenssh-keys

I'm only working with terminal in order to create a user on a linux machine (ec2).

When creating a new user and then generating an ssh key for this user
ssh-keygen -f rsa I do this

I then get a rsa.pub file in the users home directory and I also have an .ssh directory with an authorized_keys file.

What I don't know now is how can I download the private key as a file to my computer in order to connect to the instance.

Thanks
Matt

Best Answer

You can use scp to transfer a file from the server.

scp -i <ec2-ssh-key> ec2-user@your-instance:/path/to/rsa <local_path>

It is also possible just to copy the content of a private key and paste into a local file.

e.g.

cat ~/.ssh/rsa