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
- Generate a key pair:
ssh-keygen -t ed25519 -C "[email protected]"
- Copy the public key:
ssh-copy-id user@remote-server
- Test login:
ssh user@remote-server
- Disable password authentication in
/etc/ssh/sshd_configfor security.
Tips
- Use a passphrase on your private key for extra security.
- Store keys in
~/.ssh/with permissions600. - Use
ssh-agentto avoid typing passphrases repeatedly.
Common issues
ssh-copy-idfails if password auth is already disabled; manually append the key.- Wrong file permissions on
~/.sshcan prevent key authentication.