How to configure SSH key-based login

· Category: Linux

Short answer

Generate an SSH key pair and copy the public key to the remote server to authenticate without a password.

Steps

  1. Generate a key pair:
ssh-keygen -t ed25519 -C "[email protected]"
  1. Copy the public key:
ssh-copy-id user@remote-server
  1. Test login:
ssh user@remote-server
  1. Disable password authentication in /etc/ssh/sshd_config for security.

Tips

  • Use a passphrase on your private key for extra security.
  • Store keys in ~/.ssh/ with permissions 600.
  • Use ssh-agent to avoid typing passphrases repeatedly.

Common issues

  • ssh-copy-id fails if password auth is already disabled; manually append the key.
  • Wrong file permissions on ~/.ssh can prevent key authentication.