How to use the authorized_keys Analyzer
- On the server, run cat ~/.ssh/authorized_keys and copy the output, or open the file.
- Paste it in; the report updates as you type.
- Work through the findings from the top: each names its line and what to change.
- Edit the file on the server, keeping it at chmod 600, and test a login in a second terminal before closing the first.
What is the authorized_keys file?
~/.ssh/authorized_keys is the list of public keys that may log in to one account over SSH: anyone holding the private half of a key on that list gets in, with no password. Each line is one key, written as optional options, the key type, the key in base64 and a comment, as defined under AUTHORIZED_KEYS FILE FORMAT in the sshd(8) man page.
Because adding a line is so easy, the file tends to collect keys nobody can account for: old laptops, people who left, a CI job from two years ago. This analyzer reads it the way sshd does and tells you what each line is.
How sshd reads each line
restrict,command="/usr/local/bin/backup.sh",from="203.0.113.0/24" ssh-ed25519 AAAAC3Nz… backup@nas- Options come first, separated by commas with no spaces. A value goes in double quotes and may contain spaces and commas. The options end at the first space outside quotes.
- The key type must match the type inside the key:
ssh-ed25519,ssh-rsa,ecdsa-sha2-nistp256,sk-ssh-ed25519@openssh.comand so on. - The key is base64 on the same line. A key wrapped onto two lines is two broken lines.
- The comment is everything after the key. sshd ignores it, so it is the only record of whose key it is.
Blank lines and lines starting with # are skipped. An unknown option, a duplicated command= or an unreadable expiry-time= makes sshd reject the whole line, so that key silently stops working.
What the analyzer checks
| Finding | Why it matters |
|---|---|
| DSA key | Limited to 1024 bits; disabled by default in OpenSSH 7.0 and removed in 10.0 |
| RSA under 2048 bits | Disallowed by NIST since 2013; under 1024 bits OpenSSH refuses it outright |
| RSA 2048 to 3071 bits | Acceptable until 2030 per NIST SP 800-57, but not for a new key |
| Same key twice, different options | sshd tries every matching line, so the least restricted copy wins |
| No comment | Nobody can say whose key it is when it is time to remove it |
command= without restrict | A forced command does not stop port or agent forwarding |
environment= | Only works with PermitUserEnvironment, which can defeat a forced command |
no-touch-required on a FIDO key | The key signs without anyone touching it |
Expired expiry-time= | sshd refuses the key; the line is dead weight |
| A private key pasted in | Anyone who can read the file now has that key |
Each key also gets its SHA256 fingerprint, the same value ssh-keygen -lf ~/.ssh/authorized_keys prints, so you can match lines against the keys people hold.
A worked example: locking down an automation key
A backup server logs in to run one script. Unrestricted, its key can open a shell, forward ports into your private network and forward an agent. Restricted, it can only run the script, only from the backup server's network:
restrict,from="203.0.113.0/24",command="/usr/local/bin/backup.sh" ssh-ed25519 AAAAC3Nz… backup@nas 2026-10restrict turns off port, agent and X11 forwarding, the pty and ~/.ssh/rc, including any added in future OpenSSH releases. Add back only what the job needs, for example restrict,pty. The original command the client asked for is in SSH_ORIGINAL_COMMAND, which the script can check.
To match a line to a person, ask them for ssh-keygen -lf ~/.ssh/id_ed25519.pub and compare it with the fingerprint in the table.
Common errors and how to fix them
- A key that should work is refused. Check the line is not wrapped, the options have no spaces outside quotes, and the file is
chmod 600and~/.sshischmod 700, both owned by the user. WithStrictModes yes, the default, sshd ignores the file if it,~/.sshor the home directory can be written by other users. - "Permission denied (publickey)" right after editing. The edit broke a line. Keep a session open while you change the file and test from a second terminal.
- A PuTTY key that never works. Lines starting
---- BEGIN SSH2 PUBLIC KEY ----are the RFC 4716 format; convert withssh-keygen -i -f key.puband paste the one-line result. - Removing someone's access. Delete their line and also check
/etc/ssh/sshd_configfor anAuthorizedKeysFilethat points somewhere else.
Managing keys with Shipown
Shipown's deploy users feature creates non-root accounts on a server, assigns people's public keys to them, sets scoped sudo rules and revokes an account when it is no longer needed, over SSH from your desktop. For the SSH daemon's own settings, use the sshd_config analyzer; for a new key, the SSH key generator.
Frequently asked questions
What is the correct format of an authorized_keys line?
Optional comma-separated options, then the key type, the base64 key and a comment, all on one line, for example: ssh-ed25519 AAAAC3Nz… alice@laptop. Values with spaces go in double quotes.
What permissions should authorized_keys have?
600 for the file and 700 for ~/.ssh, both owned by the account. With StrictModes on, the default, sshd ignores a file that other users can write.
How do I restrict an SSH key to one command?
Start its line with restrict,command="/path/to/script". restrict turns off forwarding and the pty, and the forced command runs instead of anything the client asks for.
How do I find whose key is in authorized_keys?
Compare fingerprints. Run ssh-keygen -lf ~/.ssh/authorized_keys on the server, and ask each person for ssh-keygen -lf on their public key; matching SHA256 values are the same key.
Are DSA keys still allowed in authorized_keys?
Not by current OpenSSH. DSA was disabled by default in OpenSSH 7.0 and removed in 10.0, so those lines either do nothing or keep a weak key alive on an old server. Replace them with Ed25519 keys.
Does sshd use the comment at the end of a key?
No, sshd ignores it. It exists only for people, which is why a key without a comment is hard to account for later.