To use SSH keys on Linux for secure, password-less authentication, follow these steps:
1. Generate an SSH Key Pair
Or for RSA:
Output: Two files created:
- Private key:
~/.ssh/id_ed25519(keep this secure; never share it). - Public key:
~/.ssh/id_ed25519.pub(copy to servers).
2. Copy the Public Key to the Server
Method 1: Use ssh-copy-id:
ssh-copy-id -i ~/.ssh/id_ed25519.pub username@server_ip- Enter your server password when prompted.
- This appends your public key to
~/.ssh/authorized_keyson the server.
Method 2: Manual Copy:
Display your public key:
cat ~/.ssh/id_ed25519.pubLog in to the server and paste the key into ~/.ssh/authorized_keys:
mkdir -p ~/.sshecho "public_key_string" >> ~/.ssh/authorized_keyschmod 700 ~/.sshchmod 600 ~/.ssh/authorized_keys3. Connect via SSH
ssh -i ~/.ssh/custom_key_name username@server_ipTroubleshooting
chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_ed25519*