SSH key authentication lets users log into servers without the need to use their user’s passwords which increases security.
Step 1: Create a key (if you don't already have one)
bash
ssh-keygen -t ed25519Ed25519 is the recommended modern key type — it's faster, more secure, and produces shorter keys than RSA. If you're on an older system that doesn't support Ed25519, fall back to
ssh-keygen -t rsa -b 4096. For extra security, add a passphrase to your key when prompted.
Step 2: Copy the key to your server
bash
cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keysStep 3: Disable root login and password login for users
Modify /etc/ssh/sshd_config configuration file to include the following (if not already there):
nginx
PermitRootLogin no
PasswordAuthentication noStep 4: Restart your `ssh` service
bash
sudo systemctl reload sshd.serviceKeep reading
Control Root Login Using SSH
How to disable password-based root login by replacing it with SSH key-based login.
·1 min read
