How To Create Keys For SSH Access To Your VPS Print

  • 0

Using public / private key pairs to access your VPS SSH service is a great way to improve the security of your UK VPS.

 

Linux Command Line (CLI)

Most Linux distributions already have ssh_keygen installed.

To generate a new SSH key pair, perform the following from your Linux console:

ssh-keygen -b 2048 -t rsa
 
Hit ENTER to accept the defaults file location, making note of where the generated files will be stored.
For example:
 
Enter file in which to save the key (/root/.ssh/id_rsa):
 
When asked to enter a passphrase, enter a secure passphrase & make a note of it.
For example:
 
Enter passphrase (empty for no passphrase):
 
Your private & public keys will be generated in the directory you choose.
 

Windows PuTTY

If you have PuTTY installed you should already have puttygen.exe on your Windows computer.
To run puttygen.exe you'll need to open your Windows File Explorer & navigate to the directory that PuTTY is installed in.
This is usually C:\Program Files (x86)\PuTTY.
 
From there:
  • Double-click puttygen.exe to start the program
  • In the program window that opens, make sure the following parameters are set:
    • Type of key to generate: SSH-2 RSA
    • Number of bits in the generated key: 2048
  • Click the Generate button
  • Move your mouse cursor around the blank area on the window to generate random data
  • The key that is generated will appear in the Public key for pasting into OpenSSH authorized_keys box
  • In the Key comment: field enter a name you would like to identify the key by
  • Enter your passphrase in the Key passphraseConfirm passphrase fields
  • IMPORTANT: make sure you don't lose the passphrase!
  • Click the Save private key button
  • If you're going to use the key with PuTTY save it as a PPK format, otherwise:
    • Click Conversions
    • Click Export OpenSSH key
    • Choose a name to save the key as. No file extension is required, but people usually use the .ssh extension
  • Copy the Public key for pasting into OpenSSH authorized_keys (make sure you copy all the key characters)
  • Open a text editor & past the key into the editor
  • Save the key with a name of your choosing (e.g. the same name as the Key Comment used earlier), but make sure it has a .pub file extension

Conclusion

The public / private key pair you created above can be used to access your Farbyte VPS using SSH certificate authentication.

On the VPS you want to access, simply add the public key to the ~/.ssh/authorized_keys file of the user you want to connect to the server as.

You can change the name & location of the file that is designated as the authorised key file in your /etc/ssh/sshd_config file (AuthorizedKeysFile setting) if you like.

Also, make sure that you set PubkeyAuthentication to yes in your /etc/ssh/sshd_config file & restart your SSH service.

You will then need to configure your SSH client software to use the certificate when connecting to the VPS.

The process of configuring the SSH client software varies depending on the software you're using.

Once you're happy that you can connect to your VPS using key authentication you can disable the use of a password to access SSH.

This can be done by setting the PasswordAuthentication setting to no in your /etc/ssh/sshd_config file & restarting the SSH service/daemon.


Was this answer helpful?

« Back