Setting up and Using your public key

Public keys are a handy way to manage ssh authentication without having to type in your password. To use your public key you first need to generate one. To do this on your home machine type the following on the termninal:

$> ssh-keygen

Type enter to accept the default location and enter an optional passphrase. (You can leave it blank.) This creates a directory called .ssh in your home directory (hidden because of the leading period). The contents are:

$> ls .ssh

The id_rsa file is your private key. Do not share it! The file is your public key, and you can share it with anyone. If you open it up it contains something like the following:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5/Sv6el1KPe8DbihilmigqN04qi
rUu+pl3sBdMZcgkaZOpoU/miT42Kf2SBQYUH48dRs5YBu1tBZD me@mylaptop

Your public key contains a method for encrypting messages that only your private key can decode. To put your public key on a server, first create the .ssh directory on the server and give it the proper permissions using chmod

$> mkdir .ssh

$> chmod 700 .ssh

$> cd .ssh

Open a file called authorized_keys in the .ssh directory and paste the text of your public key in it. Then change the permissions using chmod

$> chmod 600 authorized_keys

Now log out and log back in using ssh. If you entered a passphrase use it when prompted; otherwise you will be logged in directly without having to type a password.