Select Your OS:
Whether you're setting up a local machine or a cloud-based server, setting up SSH keys is something you'll do time and time again. SSH authentication is more secure than plain text password authentication because the remote server will verify against the local server's private key. Essentially, you can whitelist the computers/servers that have access to the target machine.
If you already have a remote server to connect to, you can skip the prerequisites. If not, the prerequisites will show you how to spin up a virtual machine that you can practice SSHing into.
- Open PuttyGen.
- Select SSH-2 RSA under Type of key to generate and click the Generate button.
- Move your mouse over the area below the progress bar to generate randomness.
- Type your passphrase in the Key passphrase field.
- Click Save private key to save the private key to your local machine. You will need this to SSH into remote machines.
- Right-click inside the text field labeled Public key for pasting into the OpenSSH authorized_keys file and choose Select All.
- Right click in the same field and left click Copy.
- Run the following commands on the local machine (your desktop/laptop's main operating system).
- The following message will be output to the terminal, indicating that the new ssh key was created.
- Now answer the following prompts. The key's filename and passphrase are optional. We won't override the key or type in a passphrase, for training purposes. Unless you've indicated a path and filename, you'll find the key at the following location:
- Anytime you need to print the public key to the screen, run
cat ~/.ssh/id_rsa.pubin the shell.
ssh-keygen -t rsa -C "firstname.lastname@example.org"
Generating public/private rsa key pair.
The private key will be located in the same directory as the public key.
Enter file in which to save the key (/home/user/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again:
The following SSH key details will now be output to your screen.
Your identification has been saved in test. Your public key has been saved in test.pub. The key fingerprint is: 52:e6:74:09:89:96:13:80:c4:41:5f:a9:1f:14:cd:33 roblayton@local The key's randomart image is: +--[ RSA 2048]----+ | ++o..+O.. | | o. .B E. . | | .+ .+oo | | . .= . | | ...S | | .. | | | | | | | +-----------------+