Technology
Log in with SSH keys
Demo Author
Published: 1 min read

A key pair is safer than a password: the private key never leaves your computer, and nobody can guess it. Here is how to switch.
Create a key pair
On your own computer, run ssh-keygen -t ed25519 -C "maya@laptop" and accept the default location. Add a passphrase if other people use the computer.
Copy the public key to the server
ssh-copy-id [email protected] adds your public key to the server. Log in again: it should no longer ask for the server password.
Keep your current session open until the new login works. If something goes wrong, you can still fix it from there.
Turn off password logins
Open /etc/ssh/sshd_config, set PasswordAuthentication no and PermitRootLogin no, then restart the service: sudo systemctl restart ssh.

Give a second admin access
Each person gets their own key. Add their public key on its own line in ~/.ssh/authorized_keys, and remove it when they leave.
Related posts
Set up your first server
GuidesFrom choosing a plan to your first login, with updates installed and a firewall in place. About ten minutes.

Welcome to the new Sun-VPS website
NewsThe new site is live in Thai, English and Vietnamese: plans explained in plain words, and guides that help you go live.
