SSH Keys
SSH keys are more secure than passwords and more convenient: no more credential entry at each access.
How It Works
You generate a key pair:
- Private key: stays on your computer (never share)
- Public key: goes on server
1. Generate Key Pair
On Linux / macOS / Windows (PowerShell):
ssh-keygen -t ed25519 -C "my-server-key"
You'll be asked where to save key (press Enter for default ~/.ssh/id_ed25519) and optional passphrase.
2. Copy Public Key to Server
ssh-copy-id root@SERVER_IP
If SSH port is different from 22:
ssh-copy-id -p PORT root@SERVER_IP
Manual alternative (if ssh-copy-id not available):
cat ~/.ssh/id_ed25519.pub | ssh root@SERVER_IP "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
3. Verify It Works
ssh root@SERVER_IP
If connection works without password, keys are configured correctly.
4. Disable Password Access (optional but recommended)
Once verified keys work, disable login via password:
nano /etc/ssh/sshd_config
Find and set:
PasswordAuthentication no
PermitRootLogin prohibit-password
Restart SSH:
systemctl restart sshd
Before disabling password access, ensure SSH keys work correctly. Otherwise you risk locking yourself out.
Manage Multiple Keys (SSH Config)
If you have multiple servers, create ~/.ssh/config to manage them easily:
Host my-vps
HostName SERVER_IP
User root
Port 22
IdentityFile ~/.ssh/id_ed25519
Host other-server
HostName OTHER_SERVER_IP
User ubuntu
Port 2222
IdentityFile ~/.ssh/id_ed25519
Then access simply with:
ssh my-vps
Gerelateerde artikelen
Change Root Password
How to change your server's root password and how to recover it if forgotten
First Server Access
What to do immediately after activating your VPS or VDS
SSH Access with PuTTY and FileZilla
How to connect to VPS via SSH with PuTTY and manage files with FileZilla on Windows
