SSH Keys and Passwordless Login: ed25519, Config Aliases, and ssh-agent
OpenSSH 9.6p1, zero packages: ed25519 256-bit + RSA 4096-bit keys, private 600, public 644, 1 identity in the agent, config resolving to deploy@192.0.2.10:2222. ssh-copy-id and real login not verified here — no sshd on this machine.

Anyone who logs into servers several times a day knows the pain of passwords. Typing a password on every login, mistyping it precisely because it is complex, and still not feeling safe afterwards: passwords get stuffed, phished, and brute-forced over and over. Key login fixes this. You generate a key pair on your own machine, put the public key on the server, and keep the private key in your hands. At login time the server poses a challenge with your public key, your machine answers it with the private key, and if the answer checks out you are in — no password typed, and no password ever crossing the network. The process is called signature verification; the details do not matter, the conclusion does: your private key is your identity, and whoever holds it can log in as you.
First, the demo setup and one honest boundary. Every command in this guide was actually run on this machine: OpenSSH 9.6p1, zero third-party packages. The demo script is demo254_g2.sh. It generates keys, reads fingerprints, writes a config, loads the agent and checks permissions, all on this machine, all exiting 0. But this machine has no sshd installed — there is no SSH server side here — so two steps cannot be run locally: copying the public key with ssh-copy-id, and a real passwordless login. Wherever this article touches those two steps it says so plainly, marked "not verified on this machine", with the steps taken from the OpenSSH manual; run them on a machine with a server first and verify them there. Every other number in the article can be found in the demo's Chinese and English transcripts.
Generating a key takes one line: ssh-keygen -t ed25519 -C "vibe254@example". The -t flag is the key type, and ed25519 is the preferred type today — short and fast. The -C flag is a comment, usually an email address or a purpose, so you can tell later what a key is for. The command asks two questions: where to save the key — the default is ~/.ssh/id_ed25519, just press Enter — and whether to set a passphrase for the private key. The demo presses Enter there too, meaning no passphrase. Whether to set a passphrase gets its own section later; for now, remember that the demo keys have no passphrase, are throwaway demo keys, and must never be used to log into a real server. After generation, ~/.ssh holds two files: id_ed25519, the private key, and id_ed25519.pub, the public key. The private key stays with you only; the public key can be handed to anyone, because the public key itself is not a secret.
Permissions are the first line of defense for a key, and sections 1 and 6 of the demo script verify exactly that. The private key must be 600, readable and writable only by you; the public key can be 644, readable by others is fine. After generating the keys, the demo script explicitly runs chmod 600 on the private key and chmod 644 on the public key, then checks with stat: private 600, public 644. Here is a detail only a real run would surface: this machine's umask is 0007, so a freshly generated public key comes out as 640 by default, not 644. If you see 640 for a public key on another machine, do not panic — that is the umask at work, and a manual chmod 644 fixes it. Section 6 of the demo also runs a permissions experiment: the private key is set to 777, then back to 600, and stat reports 777 and then 600. Once a private key is readable by others, the SSH client refuses to use it at all, preferring a failed login over logging in with an exposed private key. That is not a bug; OpenSSH is designed that way on purpose.
The fingerprint is how you recognize a key. ssh-keygen -lf id_ed25519 prints one line: 256 SHA256:<fingerprint> vibe254@example (ED25519). The 256 is the key size — ed25519 is always 256 bits. The string after SHA256 is a hash computed from the public key; the demo script replaces it with <fingerprint> because every generated key is different and so is its fingerprint, and writing down one specific value would be meaningless. The (ED25519) in parentheses is the type, and the comment is the -C from generation time. Fingerprints matter the first time you connect to a server: the server shows you its host fingerprint and asks you to confirm it, and you compare it against the fingerprint the hosting provider gave you. If it does not match, someone may be impersonating the server — do not press yes, go and check first.
Private and public keys correspond one to one, and losing the public key is no problem: the private key can regenerate it with ssh-keygen -y -f id_ed25519, which prints the public key again. Section 2 of the demo does exactly this: the recovered public key starts with ssh-ed25519, the key body is 68 characters, and the comment is vibe254@example. Sixty-eight characters is the fixed length of an ed25519 public key body — the same on every run. The reverse does not work: a public key alone cannot produce the private key. Once a private key is lost or leaked, there is no way to get it back; the only fix is to retire the pair, generate a new one, and put the new public key on the server. That is why guarding the private key matters far more than guarding the public key: public keys can be posted anywhere, a lost private key is simply lost.
RSA 4096 is the other key in the demo, generated in section 3. The command is ssh-keygen -t rsa -b 4096, where -b sets the size to 4096 bits. The fingerprint line reads 4096 SHA256:<fingerprint> vibe254@example (RSA). When would you still use RSA? Two cases: a server too old to support ed25519, or a counterparty that explicitly requires RSA. Otherwise, ed25519 is the default: shorter keys, faster generation, faster signing, and plenty secure today. The rule for choosing a key type is one sentence: use ed25519 unless you have a compatibility reason, then use RSA 4096. Do not use 1024-bit RSA or DSA — both appear in old tutorials and are no longer considered safe enough today.
Getting the public key onto the server is the most important step in the whole flow, and also the one this machine cannot verify. The standard way is ssh-copy-id -i ~/.ssh/id_ed25519.pub deploy@192.0.2.10, which appends your public key to ~/.ssh/authorized_keys on the server. The authorized_keys format is simple: one public key per line, starting with the key type such as ssh-ed25519, then the key body, then the comment. Section 6 of the demo simulates this file locally: the generated public key is written into an authorized_keys, which counts 1 line, and the first field is ssh-ed25519. The local part is verified and the numbers are solid. But ssh-copy-id itself, and the real passwordless login that follows, cannot run here because there is no sshd, so both steps are marked not verified on this machine. The steps follow the OpenSSH manual; run them on a test server first, then on production. You can also copy the public key by hand: append the contents of id_ed25519.pub to the server's authorized_keys. The effect is the same as ssh-copy-id, but be careful not to overwrite what is already there — append with >>, not >.
Typing the server address, username and port by hand every time is tedious and error-prone, and ~/.ssh/config solves it. The demo config is four lines: Host vibe254 is a nickname for the server, HostName 192.0.2.10 is the real address, User deploy is the login name, Port 2222 is the port, and IdentityFile ~/.ssh/id_ed25519 says which private key to use. Once written, the login command shrinks from ssh -p 2222 -i ~/.ssh/id_ed25519 deploy@192.0.2.10 to ssh vibe254 — one alias replaces all of it. You do not need to log in to check whether the config is right: ssh -G prints the resolved result. Section 4 of the demo runs ssh -G -T -F config vibe254, and the output is user deploy, hostname 192.0.2.10, port 2222, identityfile ~/.ssh/id_ed25519 — exactly what the config file says. Two notes: 192.0.2.10 is a documentation-only example address (the TEST-NET-1 range), not a real server — the demo uses it precisely so it points at no real machine — and 2222 is a demo port; real servers default to 22. The -T after ssh -G disables pseudo-terminal allocation; without it, running the demo outside a terminal adds a "Pseudo-terminal will not be allocated" warning line, and with it the output is clean.
Four steps in, the whole chain looks like this: generate a key pair, put the public key on the server, write an alias in config, load the key into the agent once — and after that, ssh with the alias logs in without a password. The chart shows the four steps and the key numbers from the demo.

ssh-agent is for "load once, never type the passphrase again". Without an agent, a passphrase-protected private key asks for its passphrase on every login. With an agent, you load the key once, type the passphrase once, and later logins need no passphrase. Section 5 of the demo runs this flow: ssh-agent -s starts the agent, ssh-add id_ed25519 loads the key, ssh-add -l counts 1 identity in the agent, and ssh-agent -k stops the agent. The demo keys have no passphrase, so loading them asks for nothing; in real use a key should have a passphrase, you type it once at load time, and never again afterwards. The agent's security boundary should be clear: the agent only runs on your own machine and the private key never leaves it — but while the agent is unlocked, any process that can reach the agent can use your key to log in, so stop the agent when you are done, or at least do not leave an unlocked agent sitting on an unattended computer.
A private key's passphrase can be changed without generating a new key: ssh-keygen -p -P old-passphrase -N new-passphrase -f private-key-file. Verified on this machine with a copy of the demo key: after setting the passphrase s3cret-pass, unlocking with the new passphrase succeeded, and unlocking with a wrong passphrase was rejected with exit code 255. Changing the passphrase does not touch the public key, and nothing on the server needs to change, because the passphrase only encrypts the private key file itself — changing it does not change the key pair. How strong the passphrase should be depends on what the key can reach: a key that only reaches a test server can have a simpler passphrase; a key that reaches production servers and code repositories deserves a serious one. A forgotten passphrase cannot be recovered either — the only fix is a fresh key pair, exactly like a lost private key.
When passwordless login is set up but the connection fails, troubleshooting has a fixed order: client first, then server. On the client: is the private key 600, was the public key sent to the right file, is the config alias spelled right, does ssh -G resolve to what you expect? Section 7 of the demo shows one failure mode: with no sshd on this machine, ssh to 127.0.0.1 port 22 returns Connection refused with exit code 255. Connection refused means nothing is listening on that port on that machine, and it has nothing to do with keys — if you see it on a real server, check first whether sshd is running and whether the port is right, before suspecting the keys. On the server, the checks are mostly permissions: the ~/.ssh directory should be 700, authorized_keys should be 600, and the home directory itself must not be writable by others. These three are from the manual, not verified on a server here: OpenSSH servers enable StrictModes by default, and wrong permissions mean key login is refused outright, without an extra word of explanation. Another common case is Permission denied (publickey), which means the server got your key request but found no matching public key in authorized_keys — go back and check that the public key was copied, and copied into the right user's home directory.
When one key is not enough, the fix is per-host config. Sooner or later you will have several keys: one pair for work servers, one for personal servers, one for code hosting. The way to manage them is to write a separate IdentityFile under each Host in config, so each server uses its own key and they never get mixed up. Verified separately on this machine outside the demo: one Host with two IdentityFile lines plus IdentitiesOnly yes resolves with ssh -G to two identityfile lines and identitiesonly yes. IdentitiesOnly means "use only the keys named in this config, do not try the others in the agent". Without it, the client tries every key in the agent one by one, and too many failed attempts can make the server treat you as a brute-force attack and refuse you. Once you have several keys, IdentitiesOnly is a cheap line that is almost always worth adding.
Private key backups deserve their own note. The private key file itself is the backup: copy id_ed25519 to an encrypted USB stick or an encrypted backup drive and store it. The backup medium must be under your control and encrypted — never drop a private key into an unencrypted cloud drive or a chat log. Verified on this machine: a freshly generated private key file starts with the line -----BEGIN OPENSSH PRIVATE KEY-----, the modern OpenSSH default format; the -----BEGIN RSA PRIVATE KEY----- header seen in old tutorials is the older PEM format, and key generation no longer defaults to it. To restore a backup, copy the file back into ~/.ssh, set its permissions back to 600, and it works. After restoring, verify it first with ssh-keygen -y to check the private key still works, then with ssh-keygen -lf to compare the fingerprint — only when both check out is the backup a good backup.
Key management has a few rules worth copying verbatim. First, never send a private key anywhere: not to a chat group, not into a support ticket, not into a code repository, not onto a cloud drive. Public keys can be posted anywhere; private keys should not even appear in a screenshot. Second, one device, one key pair: one pair for the laptop, one for the desktop, and separate pairs for servers logging into each other. If one device is lost, you only retire that pair instead of changing keys everywhere. Third, retiring a key means deleting its line from the server's authorized_keys — it takes effect immediately, with no service restart. Fourth, rotate keys on a schedule, but at minimum in three situations: changing computers, changing jobs, or suspecting a leak. Fifth, do not copy one private key onto many machines: if any one of those machines has a problem, every server that trusts that key needs a new public key, which costs far more than generating separate pairs from the start.
The first connection to a new server has one more small step: host key confirmation. The first time ssh connects, the client shows the server's host fingerprint and asks whether to trust this machine. Press yes and the fingerprint goes into ~/.ssh/known_hosts, and later connections stop asking. Do not press yes blindly: the fingerprint should match the one from the hosting provider, the cloud console, or a colleague. If it does not match, stop and check first. As known_hosts accumulates fingerprints, a server that was reinstalled gets a new host key, and the next connection warns WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED — the client telling you the server's identity changed. It could be a reinstall, or it could be someone impersonating the server. Once you confirm it was a reinstall, remove the old record with ssh-keygen -R hostname, connect again, and confirm once more. This command has no real server to verify against on this machine; it follows the manual, so check your own situation before running it.
Once key login works, people ask whether to turn password login off. The answer is yes — but the order must not be wrong. First confirm that key login really works, then turn password login off, then immediately open a fresh window and log in again with the key to confirm you did not lock yourself out, and only then close the old session. Turning password login off means editing the sshd configuration on the server, setting PasswordAuthentication to no, and restarting the sshd service. This whole step has no sshd to verify against on this machine, so it follows the OpenSSH manual — run it on a test server first. Getting the order wrong is expensive: turn the password off first and discover the key is broken afterwards, and the server is unreachable except through the cloud provider's rescue console. So the rule is worth memorizing: a working key is the precondition, turning the password off is the finishing step, and no step in between gets skipped.
Finally, a checklist that gets passwordless login running. Step one: on your own machine, run ssh-keygen -t ed25519 -C "your email", generate a key pair, and confirm the private key is 600. Step two: look at the fingerprint with ssh-keygen -lf and confirm it is 256-bit ED25519. Step three: copy the public key into the server's authorized_keys and count the lines to confirm one was added. Step four: give the server a nickname in ~/.ssh/config and check the resolution with ssh -G. Step five: load a passphrase-protected key into ssh-agent once, and confirm with ssh-add -l that the agent holds 1 identity. Step six: log in once with the alias — and only after that works, turn password login off, but never before confirming the key login, or you will lock yourself out. The demo script demo254_g2.sh and the Chinese and English transcripts are in the draft directory. Reproducing them takes two commands: bash demo254_g2.sh --lang zh and bash demo254_g2.sh --lang en. Both exit with code 0: ed25519 256-bit, RSA 4096-bit, private 600, public 644, 1 identity in the agent, config resolving to deploy@192.0.2.10:2222, numbers identical. The only steps not run in the demo are ssh-copy-id and the real login, because this machine has no sshd; run those on a test server first, following the manual.
Comments (0)
Sources
Related articles
tmux 3.4, zero packages: 1 session, 2 windows, 3 panes; the logs window prints 1 to 5, editor panes report ready. Detach with Ctrl-b d, reattach with tmux attach — the session outlives the connection. Mouse, prefix key and history limit in ~/.tmux.conf included.
GCC 13.3.0, C17, zero packages: a first C program, sizeof results 1/2/4/8/8/4/8/8, sum 1..100 is 5050, 10! is 3628800, 8 numbers sorted, 3 books total 1088 pages, 3 file lines and 70 chars read back. Preprocessing alone expands 3 lines to 815.
6 files, 24 lines, 4 TODO lines; false | true gives PIPESTATUS 1 and 0, pipefail on exits 1, off exits 0; a spaced filename splits into 2 words unquoted, 1 quoted; backup 6 files, 445 bytes. Bash 5.2.21, measured.