Setting Up Secure SSH Access for Plesk Vhosts (macOS/Linux)¶
This guide explains how to set up key-based SSH access for specific Plesk system users. This method is more secure than using passwords and allows you to manage multiple websites (vhosts) easily.
1. Generate a New SSH Key Pair¶
On your local machine (Mac/Linux), generate a unique key pair for the server. Using a unique filename (rather than the default id_rsa) allows you to manage different servers/users separately.
- Open your Terminal.
-
Run the following command:
-
-t ed25519: Uses the most modern and secure encryption. -f ~/.ssh/plesk: Saves the keys asplesk(private) andplesk.pub(public) in your.sshfolder.-C: An optional comment to identify the key.
The Purpose of a Passphrase¶
During generation, you will be asked for a passphrase.
- What it is: An extra layer of encryption for your private key file.
- Why use it: If someone steals your computer or gets access to your files, they cannot use your key without the passphrase. It turns "something you have" into "something you have AND something you know."
2. Configure your Local SSH Config¶
To avoid typing long usernames and IP addresses every time, you can create a shortcut in your SSH config file.
- Open (or create) the config file:
nano ~/.ssh/config - Add an entry using this template:
Host plesk
HostName 87.106.13.58
User plesk_system_username
PreferredAuthentications publickey
IdentityFile ~/.ssh/plesk
Port 22
- Save and exit (
Ctrl+O,Enter,Ctrl+X). - Now you can connect simply by typing
ssh plesk.
To make the guide reproducible for any domain on your server, you need a quick way to find the correct usernames. Add this block to your guide, ideally under Step 3: Prepare the Server.
Optional: Identify All System Users via CLI¶
If you have many subdomains and don't want to check the Plesk GUI for each one, you can query the Plesk database directly from the terminal as root.
Run this command to see a mapping of every subdomain to its corresponding SSH/System User:
plesk db "SELECT domains.name AS domain, sys_users.login AS ssh_user FROM domains JOIN hosting ON domains.id = hosting.dom_id JOIN sys_users ON hosting.sys_user_id = sys_users.id"
3. Prepare the Server (Vhost)¶
You must place the Public Key (plesk.pub) on the server so it recognizes your Mac/Linux.
A. Identify the Target¶
Log in as root and identify the System User and the Home Directory of the vhost:
# Replace 'plesk_system_username' with the Plesk system user
getent passwd plesk_system_username | cut -d: -f6
*Output will look like: /var/www/vhosts/subdomain*
B. Enable SSH Access in Plesk¶
- Log into the Plesk GUI.
- Go to Websites & Domains > Web Hosting Access.
- Change Access to the server over SSH from "Forbidden" to
/bin/bash.
4. Install the Public Key on the Server¶
As root, you must create the .ssh directory in the vhost's home directory and set the correct permissions.
-
Create the directory:
-
Paste your public key: Open the authorized keys file:
Copy the contents of your local ~/.ssh/plesk.pub (.pub !) and paste it here as a single line.\
Save and exit (Ctrl+O, Enter, Ctrl+X).
- Set Ownership and Permissions (CRITICAL):
SSH will reject connections if these files are owned by
rootor if permissions are too loose.
5. Verify the Connection¶
From your Mac/Linux Terminal, simply run:
Why this works:¶
- Your Mac/Linux looks at
~/.ssh/configand sees that the "plesk" shortcut uses the~/.ssh/pleskprivate key. - It sends a request to the server IP as the specific system user.
- The server looks inside the vhost's
/var/www/vhosts/subdomain/.ssh/authorized_keysfile. - If the keys match and the permissions are correct (700/600), access is granted.
6. Troubleshooting "Permission Denied"¶
If you still see Permission denied (publickey) after following the steps above, use these tools as root on the server to find the "smoking gun."
A. Verify Path and Ownership¶
SSH is extremely strict. If the path to your keys is owned by root, the system user will be blocked from reading them for security reasons.
# 1. Verify the exact home directory for the user
getent passwd plesk_system_username | cut -d: -f6
# 2. Re-apply permissions to ensure the user owns their keys
TARGET_USER="plesk_system_username"
TARGET_DIR="/var/www/vhosts/subdomain"
chown -R $TARGET_USER:psacln $TARGET_DIR/.ssh
chmod 700 $TARGET_DIR/.ssh
chmod 600 $TARGET_DIR/.ssh/authorized_keys
B. Check for Locked Accounts¶
If a user account is locked or expired, SSH keys will be ignored. Check the account status:
- P: Password/Account is active (Good).
- L: Account is Locked. Unlock it with
usermod -U plesk_system_username.
C. Watch the Live Authentication Log¶
The most effective way to debug is to watch the server's auth log in real-time. Open a terminal as root and run:
Now, attempt to connect from your Mac (ssh plesk). Look for these common errors in the log:
- "Authentication refused: bad ownership or modes": The server is rejecting the folder permissions. Re-run the
chmodcommands in Step 4. - "Connection closed by authenticating user... [preauth]": This usually means the key was offered but didn't match anything in
authorized_keys. Double-check that you pasted the.pubcontent correctly as a single line.
D. Mac-Side Verbose Debugging¶
If the server logs are silent, run the connection on your Mac/Linux with the -v flag to see which identity file is being offered:
Look for the line: Offering public key: /Users/yourname/.ssh/plesk. If it is offering a different file, your ~/.ssh/config is likely pointing to the wrong path.
Workflow for new Vhosts¶
To reproduce this for any other domain on the same server:
- Find the new System User name in Plesk.
- Add a new block to your
~/.ssh/configon your Mac/Linux with a newHostnickname. - Repeat Step 4 on the server, ensuring you use the correct directory and username for the
chowncommand.