100 Useful Command-Line Utilities

by Oliver; 2014

27. ssh-keygen

On your own private computer, you can ssh into a particular server without having to type in your password. To set this up, first generate rsa ssh keys:
$ mkdir -p ~/.ssh && cd ~/.ssh
$ ssh-keygen -t rsa -b 4096 -f localkey
This will create two files on your computer, a public key:
~/.ssh/localkey.pub
and a private key:
~/.ssh/localkey
You can share your public key, but do not give anyone your private key! Suppose you want to ssh into myserver.com. Normally, that's:
$ ssh myusername@myserver.com
Add these lines to your ~/.ssh/config file:
Host Myserver
    HostName myserver.com
    User myusername
    IdentityFile ~/.ssh/localkey
Now cat your public key and paste it into:
~/.ssh/authorized_keys
on the remote machine (i.e., on myserver.com). Now on your local computer, you can ssh without a password:
$ ssh Myserver
You can also use this technique to push to github.com, without having to punch your password in each time, as described here.

<PREV   NEXT>