An SSH key is a pair of files: a private key that stays on your computer, and a public key you copy to the server. With it you log in without a password, and nobody can guess their way in.
Replace 203.0.113.10 with your server's IP address.
1. Create a key on your computer
In PowerShell (Windows) or Terminal (macOS, Linux):
ssh-keygen -t ed25519
Press Enter to accept the suggested file name. You can then choose a passphrase: a password that protects the key if your computer is lost or stolen. We recommend one.
This creates two files in the .ssh folder of your home folder: id_ed25519 (private: never share it) and id_ed25519.pub (public).
2. Copy the public key to your server
macOS and Linux:
ssh-copy-id root@203.0.113.10
Windows (PowerShell, one line):
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh root@203.0.113.10 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
You will be asked for the server password one last time.
3. Test it
ssh root@203.0.113.10
You should now get in without the server password (if you set a passphrase, you type that instead).
Keep your private key safe
- Back up the
.sshfolder somewhere safe, such as an encrypted USB drive. If you lose the private key and have switched off password login, you cannot get in. - Never send the private key by email or chat. If you need access from another computer, create a new key there and add its public key too.
NarHosts