Generating an SSH key with PuTTY on Windows and configuring it on a Linux server involves several steps.
Generating an SSH Key with PuTTY on Windows
- Download and Install PuTTY
If you haven't already, download PuTTY from here. It includes PuTTYgen, which is used for generating SSH keys.
- Open PuTTYgen
After installing, open PuTTYgen. This is the tool you'll use to generate your SSH key pair.
- Generate the Key Pair
Click on the "Generate" button and move your mouse randomly over the blank area to generate randomness for the key.
Once the key is generated, you will see a public key displayed in the window.
- Set a Passphrase (Optional)
Enter a passphrase for added security in the "Key passphrase" and "Confirm passphrase" fields. This passphrase will be required whenever you use the key.
- Save the Private Key
Click on “Save private key” and choose a secure location to save your private key (.ppk
file). Remember this location as you'll need it to connect to your server.
- Copy the Public Key
The public key displayed in the PuTTYgen window should be copied. You will need this to set up the SSH key on your Linux server.
Configuring the SSH Key on the Linux Server
- Access Your Server
Log in to your Linux server using your usual method (such as an existing SSH key, or username and password).
- Create the SSH Directory and Authorized Keys File (If Needed)
Run mkdir -p ~/.ssh
to create the directory if it doesn’t exist.
Then, touch ~/.ssh/authorized_keys
to create the file for storing authorized keys.
- Edit the Authorized Keys File
- Open the file by running
nano ~/.ssh/authorized_keys
(or use any other text editor).
- Add Your Public Key
Paste the public key you copied from PuTTYgen into this file on a new line.
Save and close the file (in nano, press CTRL + X, then Y, and Enter).
- Set Proper Permissions
Run chmod 700 ~/.ssh
and chmod 600 ~/.ssh/authorized_keys
to set the correct permissions.
- Restart SSH Service
Depending on your Linux distribution, you might need to restart the SSH service. Use service ssh restart
or systemctl restart sshd
.
Connecting with PuTTY Using Your SSH Key
- Open PuTTY
- Enter Host Details
In the “Host Name (or IP address)” field, enter your server's IP address or hostname.
- Load Your Private Key
Go to “Connection” > “SSH” > “Auth” in the PuTTY configuration menu.
Click the “Browse” button and select your private key file (.ppk
file) that you saved earlier.
- Optional: Save Session for Future Use
Return to the "Session" category, and in the "Saved Sessions" field, give your session a name and click “Save”. This allows you to quickly load these settings in the future.
- Connect to Your Server
Click “Open” to initiate the SSH connection.
If you set a passphrase for your private key, you’ll be prompted to enter it.
- Verify and Accept the Host Key (First Connection Only)
The first time you connect, you'll see a security alert about the server's host key. Verify the key, then click “Yes” or “Accept” to continue.
You're now connected to your Linux server using SSH with your PuTTY key! This setup enhances your connection's security by using SSH keys instead of traditional passwords.