~/.ssh/authorized_keys is the server-side list of public keys permitted to authenticate as a specific SSH user. On most Linux servers the file lives in that user’s home directory. Each key occupies one line. Updating the file affects new logins without restarting sshd.
If key login fails, check four things in this order: the account and path, file ownership and permissions, the key the client actually offers, and the server’s effective configuration and logs. This guide explains how to check all four on Debian/Ubuntu and how to interpret the results.
| Problem | Best first check |
|---|---|
| Where is the file? | echo "$HOME" and ls -l ~/.ssh/authorized_keys |
| Is the key line valid? | One complete ssh-ed25519 AAAA... comment line per key |
| Are modes safe? | namei -l ~/.ssh/authorized_keys |
| Is SSH using this file? | sudo /usr/sbin/sshd -T and authorizedkeysfile |
| Why was a key rejected? | Client ssh -vv plus server authentication logs |
What Is authorized_keys? File Format and Purpose
OpenSSH uses public-key authentication to verify that a client possesses the private key corresponding to an allowed public key. The private key remains on the client; the public key goes in the server account’s authorized_keys file. A file for deploy does not automatically authorize logins as root or ubuntu.
An ordinary entry has a key type, Base64 data and an optional comment. OpenSSH may also accept per-key options before the key type. Each entry must remain on one complete physical line:
ssh-ed25519 AAAA... alice@laptop
# Additional public keys can follow on separate lines
restrict,from="192.0.2.0/24" ssh-ed25519 AAAA... automation-key
These are abbreviated syntax examples, not functioning keys. Copy the entire contents of your actual .pub file; never paste a private key or a truncated AAAA... illustration. Comments are labels, not secure identities, and blank lines or lines starting with # are ignored.
Algorithm of this public key
Must be intact, not copied with line breaks
Optional human-readable label
Do not confuse this file with known_hosts. authorized_keys is on the server and authorizes user keys; known_hosts is typically on the client and records the server’s host keys. For background, see how to generate an SSH key.
Where Is authorized_keys on Linux and Ubuntu?
For a normal Linux account, the default location is ~/.ssh/authorized_keys under that account’s home directory. Examples include /home/deploy/.ssh/authorized_keys and /root/.ssh/authorized_keys. On cloud images the login user might be ubuntu, debian or another account. Do not guess: inspect the actual session.
whoami
printf 'Home: %s\n' "$HOME"
ls -ld "$HOME" "$HOME/.ssh"
ls -l "$HOME/.ssh/authorized_keys"
getent passwd "$(whoami)"

If ls says No such file or directory, the file may not exist, the account may have never used a file-based public key, or sshd may use a different path or lookup method. A missing file is not proof that the SSH service itself is broken. Check effective configuration before making changes.
How to Add a Public Key Safely
Use ssh-copy-id where available
On a Linux or macOS client, the simplest approach is to append your local public key to a remote account using ssh-copy-id. You must already have a working login method; the utility cannot bypass a server that rejects every credential.
ssh-copy-id -i ~/.ssh/id_ed25519.pub [email protected]
-i specifies the public key file. Replace the username, server name and path. After copying, open a new terminal and test with the paired private key:
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519 [email protected]
Keep your existing SSH session open until you have confirmed the new login works. For ssh-copy-id installation details see our ssh-copy-id setup steps.
If you must add a key manually
Using an existing authorized login or provider console, create the target user’s .ssh directory when necessary. Add the complete .pub line to the file with >> or a text editor, without overwriting keys already in use. The following commands run as the target login account on the server:
umask 077
mkdir -p "$HOME/.ssh"
chmod 700 "$HOME/.ssh"
touch "$HOME/.ssh/authorized_keys"
chmod 600 "$HOME/.ssh/authorized_keys"
nano "$HOME/.ssh/authorized_keys"
Paste one full public key on a single line, save the file, then verify its ownership and a new connection. Never use cat key.pub > authorized_keys on a live account: > replaces existing access entries. Do not disable password access until your replacement key works.
authorized_keys Permissions: 600, 700 and Ownership
On Unix-like OpenSSH servers, StrictModes yes normally checks that user files and the home-directory path are not dangerously writable. This can reject an otherwise correct key. Safe conventional permissions are 700 for ~/.ssh and 600 for authorized_keys; the home directory itself can commonly remain 755 or 750 if ownership is correct.
| Path | Typical mode | Why it matters |
|---|---|---|
User’s home ~ | 755 / 750 / 700 | Must not be writable by unauthorized users |
~/.ssh | 700 | Protects the SSH directory from other users |
~/.ssh/authorized_keys | 600 | Conservative writable-only-by-owner setting |
| Client private key | 600 | Different file: must remain secret on client |
A critical nuance: 600 is a safe recommendation, not a rule requiring public key material to be unreadable by everyone else. A correctly owned 644 authorized_keys may be accepted with StrictModes yes, since other users cannot write it. Ownership and write permissions across the path are what matter.
ls -ld "$HOME" "$HOME/.ssh"
stat -c '%a %U:%G %n' "$HOME/.ssh" "$HOME/.ssh/authorized_keys"
namei -l "$HOME/.ssh/authorized_keys"

namei -l lists each directory component so you can spot unsafe ownership or write access that ls -l authorized_keys alone misses.If you administer the affected account and have verified the exact path, fix ordinary modes using chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys. Incorrect ownership may require an administrator to correct the specific path. Avoid recursive chmod or chown across a live home directory; they can change unrelated files.
Read more in SSH key permissions or chmod 600.
Check the Effective AuthorizedKeysFile and StrictModes Settings
A file can be perfectly formatted and still be ignored if your daemon uses a custom AuthorizedKeysFile location, AuthorizedKeysCommand, or a user-specific Match rule. On Debian/Ubuntu, inspect the effective OpenSSH server configuration rather than relying on commented example lines in /etc/ssh/sshd_config.
sudo /usr/sbin/sshd -T | grep -E '^(authorizedkeysfile|authorizedkeyscommand|strictmodes|pubkeyauthentication) '

-T invocation does not necessarily account for connection-specific Match conditions.To evaluate a specific incoming connection, use sshd -T -C with the actual user and source address as the server sees them. The example below uses reserved documentation addresses, not a command to paste unchanged:
sudo /usr/sbin/sshd -T -C user=deploy,host=client.example,addr=192.0.2.25 | grep -E '^(authorizedkeysfile|strictmodes|pubkeyauthentication) '
Paths relative to a user’s home directory are normal; an administrator can specify absolute paths or multiple files. A different authorized-key source may be used even if ~/.ssh/authorized_keys exists. Do not change sshd_config while debugging a production connection unless you have fallback access.
Verify the Key the SSH Client Actually Offers
A correct file does not prove that the client is presenting the corresponding private key. From the client machine, start a new SSH connection with verbose logging. Here IdentitiesOnly=yes prevents extra keys offered by the agent or client configuration from obscuring which identity you are testing:
ssh -vv -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519 [email protected]
On a successful public-key exchange, look for Offering public key, then Server accepts key and ultimately an authenticated session. If the client offers a different key, fix the -i path or SSH configuration. If the expected key is rejected, check the target account, server-side file, restrictive options and server logs.

To compare fingerprints without displaying entire key lines, run ssh-keygen -lf ~/.ssh/id_ed25519.pub on the client and ssh-keygen -lf ~/.ssh/authorized_keys for authorized entries on the server (where supported). A fingerprint mismatch means you are comparing different public keys. Avoid publishing private-key paths, host addresses or account identifiers unnecessarily.
Troubleshoot Permission denied (publickey) With Real Evidence
Permission denied (publickey) means the SSH authentication attempt did not succeed using an accepted method. It does not, by itself, prove that file modes are wrong. Investigate the cause in this order:
- 1Account and file: check the login username, home directory and
AuthorizedKeysFileeffective path. - 2Key correspondence: compare public-key fingerprints and verify the identity offered by
ssh -vv. - 3Ownership and modes: inspect every path component with
namei -l, not just the final file. - 4Policy and format: check a complete key line, per-key
from=restrictions, user rules and configured authentication requirements. - 5Server logs: correlate the time of your latest attempt with the real error emitted by
sshd.
sudo journalctl -u ssh -u sshd --since '10 minutes ago' --no-pager
# On Debian/Ubuntu installations with a traditional auth.log:
sudo tail -n 60 /var/log/auth.log
Log destinations vary with the distribution and logging configuration. Look for messages about bad ownership, unacceptable keys, denied users or a failed public-key check. Do not turn off StrictModes, host-key verification or other security protections simply to make a test succeed.
Safe negative control: what an unrecognized key looks like
From a separate client, deliberately offer a disposable, unregistered key while disabling password fallback. The server should not accept this identity; a verbose SSH log can show the offered key followed by a failed authentication. This is a safe comparison with a known-good key because you do not touch the live authorized_keys file. A key rejection alone does not prove a permissions problem.

For a deeper permissions experiment, use a disposable VM or isolated non-privileged lab account. First confirm a working login under safe modes; then compare an intentionally group/world-writable authorized_keys with the server log while StrictModes yes is active, and restore secure modes immediately. Never weaken the production admin account just to take a screenshot. See our dedicated publickey troubleshooting guide.
Multiple Keys, Revocation and Restart Behavior
One account may authorize several public keys. Put each complete key on its own line, ideally with a distinct fingerprint and descriptive comment for each person or automation job. Avoid giving multiple people access to the same Linux account unless the shared identity is intentional.
To revoke a key, first identify its fingerprint, back up the file and remove only its corresponding entry. Editing the wrong line can lock out another user. Keep another admin session open until you have verified access.
cp -p ~/.ssh/authorized_keys ~/.ssh/authorized_keys.backup
ssh-keygen -lf ~/.ssh/authorized_keys
nano ~/.ssh/authorized_keys
No sshd restart is needed when you add or remove a key entry. OpenSSH checks the file for new authentication attempts. Removing a key stops future authentications with it; it does not automatically terminate sessions already logged in. Changes to sshd_config, by contrast, require separate validation and an appropriate reload/restart procedure.
Per-key options such as restrict, from="..." or command="..." can limit access, but they must be written before the key type and tested carefully. See the official OpenSSH authorized-keys format and our key removal procedure.
Windows Location and Common Questions
Where is authorized_keys on Windows OpenSSH Server?
For a normal Windows account, the usual location is C:\Users\username\.ssh\authorized_keys. For an account in the built-in Administrators group, Microsoft’s default OpenSSH configuration instead points to C:\ProgramData\ssh\administrators_authorized_keys. Windows permissions use NTFS ACLs, not chmod 600; consult Microsoft’s OpenSSH configuration guide.
Can a file have 644 instead of 600?
Often yes, when ownership and the full path are safe; the important requirement under StrictModes is avoiding unauthorized write access. 600 remains a conservative default.
Why does my file exist but SSH still rejects the key?
The server may use another AuthorizedKeysFile, the client may offer another key, a parent directory may be writable, or an account or key restriction may apply. Verify each condition instead of restarting SSH blindly.
Does the file contain a private key?
No. Put public keys in authorized_keys; keep private keys on the client. The public-key comment is optional and not an authentication factor.
References and Next Steps
For authoritative behavior, consult the OpenSSH manuals instead of copying permissions advice without context:
- OpenSSH sshd(8) — authorized_keys syntax, comments and per-key restrictions
- OpenSSH sshd_config(5) — AuthorizedKeysFile, Match and StrictModes
- Microsoft Learn — Windows OpenSSH Server configuration
The practical sequence is simple: identify the target account, inspect the file and path permissions, check the effective daemon settings, and verify the key that the client actually offers. For multiple servers, ShadeTerm can keep terminal, SFTP, editor and monitoring tools together in a server workspace.