Skip to content

Instantly share code, notes, and snippets.

@xsnpdngv
Last active February 17, 2017 12:37
Show Gist options
  • Save xsnpdngv/4e6dbc49b73b7102a46d8fc2827c628d to your computer and use it in GitHub Desktop.
Save xsnpdngv/4e6dbc49b73b7102a46d8fc2827c628d to your computer and use it in GitHub Desktop.
ssh key generation and placement for passwordless login

Generate identity locally

cd $HOME/.ssh
ssh-keygen -f id_rsa -t rsa

This will result: id_rsa, id_rsa.pub.

Setup remote

Now it is time to tell the remote account that we trust this test key. You need to include the public key (id_rsa.pub) in the file $HOME/.ssh/authorized_keys on the remote account, so log into the remote account, open up $HOME/.ssh/authorized_keys with your favourite editor and paste it at the end of the file, or:

ssh user@remote mkdir -p .ssh
cat .ssh/id_rsa.pub | ssh user@remote 'cat >> .ssh/authorized_keys'

The SSH server is paranoid, and will refuse to honour your authorized_keys settings if they have poor file permissions, so you should lock down your files and directories on the remote server:

ssh user@remote
cd $HOME
chmod go-w .
cd $HOME/.ssh
chmod 700 .
chmod 600 *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment