SSH key authentication uses a private key on your computer and a matching public key on the server. It lets you authenticate without sending the server account’s password, although the private key may still require its own passphrase.

Prepare a key on your computer

These examples use a Unix-style local shell and an existing remote account with authorised SSH access. Check for existing keys before generating another:

ls -l ~/.ssh/*.pub

If you need a new compatible RSA key, run:

ssh-keygen -t rsa -b 4096 -C 'your-label'

Choose a distinct filename if the suggested path already exists. Do not overwrite a key used elsewhere. Set a passphrase and keep the private key private; only the .pub file is copied to the server.

Install the public key

For a key saved at the default example path, run on your computer:

ssh-copy-id -i ~/.ssh/id_rsa.pub username@server-address

Use the actual account, address and key path. Add -p PORT if your SSH service uses a custom port. If ssh-copy-id is unavailable, this Unix-shell alternative appends the public key and sets the remote permissions:

cat ~/.ssh/id_rsa.pub | ssh username@server-address 'umask 077; mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys'

Verify authentication

Keep the original session open and test from another terminal:

ssh -i ~/.ssh/id_rsa -o PreferredAuthentications=publickey -o PasswordAuthentication=no username@server-address

You may be prompted for the key’s passphrase. If public-key authentication fails, check ownership, permissions and the server’s authentication settings before changing password access. Do not disable the existing login method until the intended users and recovery route have been tested.