How to Add SSH Key for a New User on VPS (Ubuntu/Debian)
You can allow other users to access your VPS securely by adding their SSH public key. This method works for Ubuntu, Debian, and similar Linux OS.
Prerequisites
-
VPS with root SSH access.
-
SSH Key from the user you want to add (public key file).
-
The user must exist on the VPS. (You can create with:
adduser username
)
Steps to Add SSH Key for a User
1. Switch to Root
Login to your VPS as root:
ssh root@your_server_ip
2. Create .ssh
Directory for the User
Replace username
with the actual username:
mkdir -p /home/username/.ssh
chmod 700 /home/username/.ssh
chown username:username /home/username/.ssh
3. Add Public Key to authorized_keys
Paste the user's public key into:
nano /home/username/.ssh/authorized_keys
-
Paste the public key here.
-
Save and exit.
chmod 600 /home/username/.ssh/authorized_keys
chown username:username /home/username/.ssh/authorized_keys
4. Test Login as User
From the user's system:
ssh username@your_server_ip
5. (Optional) Disable Password Login for All Users
To enforce SSH key login globally, follow: Disable Password Login on VPS (Ubuntu/Debian)
Notes
-
Make sure the
.ssh
directory andauthorized_keys
file have correct permissions. -
If the user can't login, check file ownership and SSH logs.
Related Articles
WHMCS Knowledgebase Title:
How to Add SSH Key for a New User on VPS (Ubuntu/Debian)
SEO Meta Description:
Learn how to add an SSH key for a new user on Ubuntu/Debian VPS to allow secure key-based access. Step-by-step guide.
Do you want me to combine all 3 articles into HTML-ready code blocks for WHMCS upload?