This is a basic walk through of how to generate an ssh key and how to set it up on a server so you can log in without having to type your password every time you want to log in.
Steps
- Generate ssh key
- Add your key to the authorized_keys file on your server.
$ ssh-keygen -t rsa -b 4096
What this does
Generates a 4096 bit RSA private / public keypair. By default this generates id_rsa
and id_rsa.pub
in your ~/.ssh
folder. If you chose a different location or file name, you'll have to edit step 2 accordingly.
$ TEMP=`cat ~/.ssh/id_rsa.pub` && ssh [user]@[server.com] "mkdir -p ~/.ssh && echo '${TEMP}' >> ~/.ssh/authorized_keys" && unset TEMP
What this does
- Copies your id_rsa.pub file to a local variable
- Makes a
~/.ssh
directory in the home folder of your server - Appends the public key to your
~/.ssh/authorized_keys
file. - Deletes the local variable we made originally to store the pubkey.
How to use
- Replace [user] and [server.com] with your server username/address in the line below.
- Alter the paths to your local public key if you chose to use something different than
~/.ssh/id_rsa.pub
. - Copy and paste this line (without the initial
$
) into your terminal and hit[enter]
Note
- This has only been tested on Mac OSX.