Set up SSH key authentication
1
Generate a key pair
On the local machine (Linux, macOS, or Windows with OpenSSH), open a terminal and run:Press Enter to accept the default file path, or enter a custom path. The command creates two files:
~/.ssh/id_ed25519— the private key. Keep this file secure; do not share it with anyone.~/.ssh/id_ed25519.pub— the public key. This is the file to copy to the server.
2
Copy the public key to the server
Run Replace
ssh-copy-id from the local machine while password access is still available:username with the account name (typically root) and server_ip with the server’s IP address.If Replace
ssh-copy-id is unavailable (Windows systems without OpenSSH 8.1 or later), append the public key manually. Log in to the server with a password, then run:public_key_content with the full contents of the id_ed25519.pub file (a single long line starting with ssh-ed25519).Connect with an SSH key
With the public key on the server, connect using the private key:~/.ssh/id_ed25519), the -i flag can be omitted — the SSH client uses it automatically.
Remove a public key
Open~/.ssh/authorized_keys on the server and delete the line containing the key to revoke: