2

I’m trying to add my friend’s public key to my Ubuntu EC2 server via the ssh terminal but I can’t find the file that I paste the key in. Can anybody explain where the file is?

3 Answers3

1

add the public key in the file (/home/ubuntu/.ssh/authorized_keys)

0

Please, note that is best to create a specific user for your friend instead of just adding his key to the default ec2-user on aws, as I stated here

Add his public key on .ssh/authorized_keys under his home directory. Remember that you have to create the .ssh dir if it does not exist and authorized_keys too. Permission for the .ssh directory are 700 and for the authorized_keys file 600

So, for example

cd .ssh

or, only if it dos not exist

mkdir .ssh
chmod 700 .ssh

then

nano authorized_keys

edit your file by putting your public ssh key and when finished

chmod 600 authorized_keys

For editing you have various solutions, this is one of the simplest, human wise.

Federico Galli
  • 918
  • 6
  • 16
0

If you only want to add his key, the best method is to have him send you his public key, and then run from your workstation:

ssh-copy-id -i friendkey.pub ec2-user@ubuntuserver

This will automatically ssh into the machine, and properly append it to the file. Advantages are lowering the risk of screwing up the file format or permissions.

With that said, I agree with Federico that you really should create another user.

Brennen Smith
  • 1,742
  • 8
  • 11