๐ Set Up SSH Key Authentication
Using SSH keys is more secure than password-based login.
๐ Step 1: Generate an SSH Key (Local Machine)โ
ssh-keygen -t ed25519 -C "[email protected]"
Press Enter to accept defaults. This creates:
~/.ssh/id_ed25519
(private key)~/.ssh/id_ed25519.pub
(public key)
๐ค Step 2: Copy Public Key to VPSโ
ssh-copy-id yourusername@your_vps_ip
OR manually copy the .pub
contents into:
~/.ssh/authorized_keys
๐งช Step 3: Test SSH Key Loginโ
In a separate terminal, test:
ssh yourusername@your_vps_ip
You should log in without a password.
๐ซ Step 4: Disable Password Authenticationโ
Once key-based login works, disable password auth:
sudo nano /etc/ssh/sshd_config
Find and edit:
PasswordAuthentication no
Save and restart:
sudo systemctl restart ssh
โ Your server now only allows SSH access using your key.