Skip to content

Instantly share code, notes, and snippets.

@tjoskar
Forked from trey/ssh_keys_osx.md
Last active December 18, 2015 13:18
Show Gist options
  • Save tjoskar/5788839 to your computer and use it in GitHub Desktop.
Save tjoskar/5788839 to your computer and use it in GitHub Desktop.

Distribute your ssh keys


If your remote username is different from your OS X username, edit your ~/.ssh/config file like so:

Host whathaveyou.com
    User remote_username

Generating your keys

On your OS X machine, enter this command:

ssh-keygen

Enter a password or don't (I didn't).

This creates a public (~/.ssh/id_rsa.pub) and private key (~/.ssh/id_rsa).

Copying the public key to the remote server

Log in to the server with ssh (with your password--for the last time).

However you want to do it, open the file ~/.ssh/authorized_keys on the remote server and paste in the contents of id_rsa.pub. Alternately, you could use scp like so:

scp ~/.ssh/id_rsa.pub [email protected]:~/.ssh/authorized_keys

(Naturally, if the file and/or folder aren't there, you'll have to create them first.)

Now change the permissions:

chmod 700 ~/.ssh/
chmod 600 ~/.ssh/authorized_keys

All done. The next time you want to ssh to the server, it won't prompt you for a password.

Sources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment