Using SSH keys with Plesk
SSH keys increase security and can be used to set up automated tasks. Read this article to learn how to set up SSH keys in a Plesk Linux environment.
The Plesk control panel does not have graphical tools to manage ssh keys. This article provides step-by-step instruction to create and manage ssh keys from the command line.
Note
Plesk is no longer included with new hosting.com plans, but it is still available on legacy Managed WordPress accounts. You can install Plesk manually on unmanaged VPS and Dedicated servers.
Note
The following instructions work with the Windows Subsystem for Linux, the Macintosh terminal, or the Linux command line.
Creating SSH keys
The following steps show how to create an SSH key on your local computer and upload the public key to the server.
- At the command prompt on the local computer, change to the.ssh directory with this command.
user@computer ~$ cd ~/.ssh
If the.ssh directory does not exist, you can create it with this command:
user@computer ~$ mkdir ~/.ssh
- When you have changed to the.ssh directory, type this command, replacing mykey with a file name of your choice.
user@computer ~$ ssh-keygen -t rsa -b 2048 -f mykey
The command will prompt for a passphrase during creation of the key. Adding a passphrase makes the key more secure but keys with passphrases cannot be used for automation. When the command completes, a public key named mykey.pub and a private key named mykey will be created in the.ssh directory.
- Copy the public key to your server using the ssh-copy-id command. Replace mykey.pub with the name you chose in the previous step. Replace user with your username on the server and replace example.com with your domain name or the IP address of the server.
user@computer ~$ ssh-copy-id -i mykey.pub -p 7822 [email protected]
You will be prompted for your password to log in. The public key will be copied to the ~/.ssh/authorized_keys file on the server.
- Once the file has been copied, you should be able to login using the following command without typing your password: Replace mykey with the name of your key file, replace user with your username on the server and replace example.com with your domain name or the IP address of the server.
user@computer ~$ ssh -i ~/.ssh/mykey -p 7822 [email protected]
Appending SSH keys
You may want to allow others to access your account or provide access to a remote service that provides their own public key. The public key may be provided as a file or you may need to cut and paste it into a file. If the file is created by pasting the key into a file, be sure there are no extra characters before or after the key. The key must be appended to the authorized_keys file on the server. To append a key, follow these steps.
-
Save or create the public key file in any convenient directory. In this example the users home directory is used. The filename should have the.pub extension.
-
Open the command prompt to the users home directory and use the ssh-copy-id command to copy the key to the server. Replace somekey.pub with the name of the file created in the previous step. Replace user with your username on the server and replace example.com with your domain name or the IP address of the server.
user@computer ~$ ssh-copy-id -i somekey.pub -p 7822 [email protected]
Related Articles
Updated 3 days ago