Managing a Virtual Private Server (VPS) is a critical task for developers, sysadmins, and businesses, and SSH (Secure Shell) is the go-to method for secure remote access. Providers like VPS.DO offer user-friendly VPS solutions with SSH access enabled out of the box, but encountering a "Permission Denied" error can halt your workflow. This error typically occurs when the SSH client fails to authenticate with the server, often due to incorrect credentials, misconfigured SSH settings, or file permission issues. This article provides a practical, step-by-step guide to diagnose and resolve "Permission Denied" errors when connecting to a Linux-based VPS via SSH.
Understanding "Permission Denied" Errors
The "Permission Denied" error in SSH usually appears as Permission denied (publickey) or Permission denied, please try again in the terminal or SSH client (e.g., PuTTY). Common causes include:
- Incorrect username or password.
- Issues with SSH key authentication (e.g., wrong key, incorrect permissions).
- Misconfigured SSH server settings (
sshd_config). - Firewall or security group restrictions.
- Disabled root login or password authentication.
Below, we outline actionable steps to troubleshoot and fix these issues.
Step-by-Step Troubleshooting
1. Verify Username and IP Address
The simplest cause of a "Permission Denied" error is an incorrect username or IP address.
- Check Credentials: Ensure you’re using the correct username (e.g.,
rootor a custom user) and VPS IP address provided by your VPS provider (e.g., in your VPS.DO dashboard or welcome email). - Test Connection: Run the SSH command with the correct details:
If your VPS uses a non-standard port (e.g., 2222), include it:ssh username@your.vps.ip.addressssh -p 2222 username@your.vps.ip.address - Verbose Mode: Use verbose output to debug:
Look for clues in the output, such as which authentication method is being attempted.ssh -v username@your.vps.ip.address
2. Confirm Password Authentication
If you’re using password-based authentication, the error may stem from an incorrect password or disabled password login.
- Reset Password: If you suspect the password is wrong, use your VPS provider’s console or control panel to reset it. Check VPS.DO’s documentation for password reset instructions.
- Check SSH Configuration: Access the VPS via an alternative method (e.g., provider console). Verify that password authentication is enabled in
/etc/ssh/sshd_config:
If it’s set toPasswordAuthentication yesno, change it toyes, save the file, and restart the SSH service:sudo systemctl restart sshd - Try Again: Test the connection with the correct password.
3. Troubleshoot SSH Key Authentication
If you’re using SSH keys and see Permission denied (publickey), the issue likely lies with the key setup.
- Verify Key Pair: Ensure you’re using the correct private key. On your local machine, check that the private key (e.g.,
~/.ssh/id_rsa) matches the public key on the VPS. - Check Key Permissions: On your local machine, private key permissions must be restrictive:
On the VPS, thechmod 600 ~/.ssh/id_rsaauthorized_keysfile and its directory must have correct permissions:chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys - Copy Public Key Correctly: Ensure the public key (e.g.,
id_rsa.pub) is in~/.ssh/authorized_keyson the VPS. If not, copy it using:
Or manually append the public key tossh-copy-id username@your.vps.ip.address~/.ssh/authorized_keys. - Check SSH Config: In
/etc/ssh/sshd_config, ensure key authentication is enabled:
Restart the SSH service after changes:PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keyssudo systemctl restart sshd
4. Check for Root Login Restrictions
Some VPS configurations disable root login for security.
- Verify Root Access: In
/etc/ssh/sshd_config, check:
If set toPermitRootLogin yesnoorprohibit-password, change toyesor create a non-root user:
Copy your SSH key to the new user’ssudo adduser newuser sudo usermod -aG sudo newuser~/.ssh/authorized_keysand test:ssh newuser@your.vps.ip.address - Restart SSH: Apply changes with:
sudo systemctl restart sshd
5. Inspect Firewall and Security Groups
A firewall or security group might block your SSH connection, indirectly causing authentication failures.
- Check VPS Firewall: Using console access, verify the SSH port (default: 22) is open. For Ubuntu/Debian:
For CentOS/RHEL:sudo ufw status sudo ufw allow 22sudo firewall-cmd --list-all sudo firewall-cmd --add-port=22/tcp --permanent sudo firewall-cmd --reload - Provider Security Groups: Log in to your VPS provider’s dashboard (e.g., VPS.DO) and ensure the SSH port is allowed in network or security group settings.
6. Test with Alternative Clients
If the default SSH client fails, try another tool to rule out client-specific issues:
- Linux/macOS: Use
sshwith verbose mode (as above) or tryopenssh-client. - Windows: Use PuTTY or MobaXterm. For PuTTY, ensure the private key (converted to
.ppkformat using PuTTYgen) is correctly loaded in the “Connection > SSH > Auth” section.
7. Check Server Logs
If you have console access, check the SSH server logs for detailed errors:
sudo tail -f /var/log/auth.log # Debian/Ubuntu
sudo tail -f /var/log/secure # CentOS/RHEL
Look for authentication failure messages or incorrect key attempts.
Best Practices to Prevent "Permission Denied" Errors
- Use SSH Keys: They’re more secure and less prone to errors than passwords.
- Backup Credentials: Store your username, password, and SSH keys securely.
- Regularly Update SSH Config: Ensure
/etc/ssh/sshd_configaligns with your authentication method. - Monitor File Permissions: Use
ls -lto verify~/.sshandauthorized_keyspermissions. - Test Changes: After modifying SSH settings, test with a new session before closing your console.
Conclusion
"Permission Denied" errors in SSH can stem from simple credential mistakes or complex configuration issues, but methodical troubleshooting can resolve them. By verifying credentials, checking SSH configurations, and ensuring proper permissions, you can restore access to your VPS. If issues persist, providers like VPS.DO often provide console access and support resources to help you recover. With these steps, you’ll be back to managing your server seamlessly.