You have to create the .ssh
directory and the authorized_keys
file the first time.
Create the .ssh
directory
mkdir ~/.ssh
Set the right permissions
chmod 700 ~/.ssh
Create the authorized_keys
file
touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
The permissions are important! It won’t work without the right permissions!
Now you can add the public key to the authorized_keys
file:
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
You have to add the public key of your computer to the authorized_keys
file of the computer you want to access using SSH Keys!
As terdon mentioned you can also just use this command:
ssh-copy-id user@host
This will put your id_rsa.pub
(in your ~/.ssh
directory) in the remote computer’s authorized_keys
file, creating the .ssh
directory and authorized_keys
file with the right permissions if necessary.
Tomado de