SSH: How to generate keys and login to your account with SSH (Mac/Linux)
If you are on a Windows-based computer, please check out this tutorial instead:
1. On your workstation (not your web hosting account), open a new terminal window.
Mac: Go to Applications > Utilities > Terminal
Linux: Depends heavily on which window manager you are using, but you should be able to use the “search” function in your window manager and find “Terminal.” Otherwise, consult the documentation for your specific window manager or operating system. Ubuntu provides some helpful information
2. Type the following command to generate a new public/private SSH key pair (and then press enter on your keyboard):
ssh-keygen -t dsa
You will receive something similar to the following output (where username is the actual username on your account):
Generating public/private dsa key pair. Enter file in which to save the key (/home/username/.ssh/id_dsa):
3. Press the enter key on your keyboard as the default location will be fine.
4. You will then be prompted for a passphrase. Make sure you set a passphrase! It should be a secure passphrase and not something that could be easily guessed or a password that you use elsewhere.
5. Once that is done, you should see something similar to the following output letting you know the key generation is complete:
Your identification has been saved in /home/username/.ssh/id_dsa. Your public key has been saved in /home/username/.ssh/id_dsa.pub. The key fingerprint is: da:5d:sd:9e:z8:79:8d:ed:13:07:61:17:8c:3d:39:cb email@example.com
6. As mentioned in the output above, your public and private keys are now stored in the following directories:
Private Key: /home/username/.ssh/id_dsa Public Key: /home/username/.ssh/id_dsa.pub
Your public key can be given to anyone and put on any server — it is public.
Your private key should remain on your workstation and NEVER be given to anyone.
It would be a good idea to make a backup of your keys and put them in a safe place, just in case.
7. In order for key authentication to work, we need to copy the public key to your Site5 account. First, login to your account via SSH as you normally would (replace the user and hostname with your actual account info):
ssh firstname.lastname@example.org or
(you will need to enter your account password)
8. Once logged in, type the following command (and press the enter key on your keyboard when done):
mkdir ~/.ssh; touch ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys; chmod 700 ~/.ssh
9. Next, open up the “authorized_keys” file we just made on the server using your favorite text editor (vim/nano/emacs). Vim will be used in this demo:
10. Find the public key you created earlier on your workstation (/home/username/.ssh/id_dsa.pub) and copy the contents of that file into the “authorized_keys” file. Make sure you copy the public key, not the private key. Save the file and close it.
Note: You will also need to ensure that any hard returns are removed so that the key only appears on a single line.
ssh-dss AAAAB……tSvH2g== user@linux
When you SSH to your account next time, you should be prompted for the passphrase of your key, but subsequent logins within that session will not require the passphrase again.