How to set up SSH keys

Created:

2016-12-18 06:54:09 UTC

Modified:

2017-08-14 10:59:02 UTC

1

Was this article helpful?


Have more questions?

Submit a request

How to set up SSH keys

Applicable to:

  • Plesk

Question

How to set up SSH keys?

Answer

  1. Create the RSA Key Pair:

    # ssh-keygen -t rsa -b 2048

    Use default location /root/.ssh/id_rsa and setup passphrase if required.

  2. The public key is now located in /root/.ssh/id_rsa.pub
    The private key (identification) is now located in /root/.ssh/id_rsa
    Note: Permissions for the private key should be 0600

  3. Copy the public key to another server using the ssh-copy-id command:

    # ssh-copy-id user@203.0.113.2

    where user and IP address should be replaced with second server's credentials.

    Alternatively, copy the content of /root/.ssh/id_rsa.pub to /root/.ssh/authorized_keys on the second server.
    Note: permissions for the authorized_keys files should be set to 0600

  4. After that, it should be possible to connect to the server for user@203.0.113.2 without a password. However, if the passphrase was set, you will be asked to enter the passphrase every time at login.

Since Plesk 12.0, SSH Keys Manager can be used to upload public part of SSH key pair to a Plesk server.

 

Additional information

  1. After successful login using the SSH key, it is possible to restrict the root login to only be permitted via SSH keys. In order to do this, open up the SSH config file:

    # vi /etc/ssh/sshd_config

    Within that file, find the line that includes PermitRootLogin and modify it to ensure that users can only connect with their SSH key:

    PermitRootLogin without-password
  2. Apply the changes:

    # service sshd reload
Have more questions? Submit a request
Please sign in to leave a comment.