If you'd like to access a Linux server from a Windows client using a key in PuTTY, you can do it with these steps:
- Download puttygen.exe from the PuTTYgen website, and run it.
- Under "Parameters", select the "ed25519" option.
- Click the "Generate" button and follow the instructions to generate some randomness.
- At the top, it will show you a public key that you can paste into the authorized_keys file. Select the entire contents of this field with your mouse, then right-click and click Copy.
- Open an SSH connection to the Linux server (host) that you wish to log into in the future and make sure that the logged-in user is the same one that you wish to use in the future.
- Open the ~/.ssh/authorized_keys file in your favorite text editor. For instance, nano ~/.ssh/authorized_keys.
- Paste the key from step # 4 as a new line at the end of the ~/.ssh/authorized_keys file. If the file doesn't exist, create it. If the folder doesn't exist, create it.
- Save the changed ~/.ssh/authorized_keys file.
- Back in puttygen.exe, click "Save private key" and enter the name "ed25519.ppk" (or your desired name). Click "Save public key" and enter a different name, such as "ed25519-public.key". puttygen.exe may ask if you are sure that you wish to save without a passphrase; click "Yes" (unless you'd rather go back and set one).
- Close puttygen.exe.
- Open your normal PuTTY client.
- In the left-hand "Category:" tree, expand the "SSH" option under "Connection". Then, click "Auth".
- Under the "Private key file for authentication:" field, click "Browse..." and select the private key that you saved earlier.
- In the left-hand "Category:" tree, click "Session".
- Enter your username and the hostname of the server into the "Host Name" box. For instance, "user@your.server.ip".
- Enter a name for your new connection in the blank field under "Saved Sessions" and click "Save".
Or, you can generate a key that you can use to access a Linux server from a Linux client:
- Open an SSH connection on the Linux system that will be the client, and make sure that the logged-in user is the same one that you wish to use in the future.
- Enter this command:
When it asks for a passphrase, you can choose to enter one or leave it blank. Using a passphrase is more secure, but it adds a manual entry step during the connection phase.
Code: Select all
ssh-keygen -t ed25519 -a 100 -f ~/.ssh/id_ed25519 - Show the contents of the file that you just created:
Code: Select all
cat ~/.ssh/id_ed25519.pub - Open an SSH connection to the Linux server (host) that you wish to log into in the future and make sure that the logged-in user is the same one that you wish to have log in.
- Open the ~/.ssh/authorized_keys file in your favorite text editor.
- Copy the key from step # 3 and paste it in as a new line at the end of the ~/.ssh/authorized_keys file.
- Save the changed ~/.ssh/authorized_keys file.
After you set up your clients and server to use SSH keys, it's best to change your password on the server to something even more complex than it was before. Since the password will only be used very rarely, you don't need it to be easy to type or remember!
To take security a step further, you can make it so that your Linux server only accepts remote SSH logins that use generated keys. If you do this, you won't be able to log in with a password, but you can still log in through the VNC console on a VDS. We recommend this, but only after you've made sure that your SSH key setup is working properly.
- Open an SSH session to your Linux server.
- In your favorite text editor, open the /etc/ssh/sshd_config file.
- Look for a line that starts with "#PasswordAuthentication" or "PasswordAuthentication". Change it to be this:
Code: Select all
PasswordAuthentication no - Look for a line that starts with "#ChallengeResponseAuthentication" or "ChallengeResponseAuthentication". Change it to be this:
Code: Select all
ChallengeResponseAuthentication no - Save the file.
- Reboot your VDS, or restart/reload the OpenSSH server (each distribution has a different way of doing this; on Gentoo, for instance, the command is /etc/init.d/sshd reload).
