How to Set Up SSH Keys for Passwordless Login
SSH keys let you log in to a server without typing your password every time. You generate a key pair on your computer, copy the public key to the server once, and from then on ssh [user]@[host] just works. This guide covers the three steps.
Step 1: generate a key pair
Run ssh-keygen on your local machine. Accept the defaults and, if you like, add a passphrase that encrypts the private key. This creates ~/.ssh/id_ed25519 (private) and id_ed25519.pub (public).
Step 2: copy the public key to the server
The ssh-copy-id command appends your public key to the server's authorized_keys. It asks for your password this one last time.
Step 3: log in without a password
That is it. Connect normally and the server accepts your key:
How it works
The server keeps your public key in ~/.ssh/authorized_keys. When you connect, the server sends a challenge that only your private key can solve, proving your identity without sending the key over the wire. Your private key never leaves your machine.
Common mistakes
The most common problems are a ~/.ssh directory with wrong permissions on the server, or the key pasted with a stray newline in authorized_keys. Fix permissions with chmod: chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys. For the basics of connecting, see ssh basics.
Keep learning
Related guides: How to Use the ssh Command to Connect to a Remote Server · How to Sync Files with rsync · Linux chmod Command: A Complete Permissions Guide. Read all tutorials on the Learn Linux blog.