What Is the authorized_keys File in Linux?
The authorized_keys file in a Linux operating system
user profile serves as a fundamental security component for the Secure
Shell (SSH) protocol. Its primary purpose is to store the public keys of
clients who are granted permission to log into that specific user
account using SSH key-based authentication. By replacing or
supplementing traditional password logins with asymmetric cryptography,
this file enables secure, automated, and passwordless remote access.
How the
authorized_keys File Works
SSH authentication relies on asymmetric public-key cryptography, which uses a mathematically linked key pair: a private key and a public key.
- The private key remains strictly with the client machine and must never be shared.
- The public key is copied to the remote Linux server
and appended to the target user's
authorized_keysfile.
When a client attempts to connect to the Linux host via SSH, the SSH
daemon (sshd) checks the target account's
authorized_keys file. The server issues a cryptographic
challenge based on the public key. If the client can prove ownership of
the corresponding private key by decrypting or signing the challenge,
the server grants access immediately without prompting for the user's
Linux password.
File Location and Format
The authorized_keys file resides inside a hidden
directory within the user's home directory:
/home/<username>/.ssh/authorized_keys
For the root user, the typical location is
/root/.ssh/authorized_keys.
The file is a standard plaintext document where each line represents a single authorized public key. A standard line includes:
- Key Type: Specifies the cryptographic algorithm
(e.g.,
ssh-ed25519orssh-rsa). - Key Data: The base64-encoded string representing the actual public key.
- Comment: An optional identifier, usually noting the creation date, email address, or hostname of the key owner.
Optional options can also precede the key type on the same line to
restrict capabilities, such as locking down the connection to a specific
IP address (from="192.168.1.50") or restricting execution
to a single predefined command.
Critical Permission Requirements
Because the authorized_keys file directly dictates who
can access an account, the SSH daemon enforces strict file system
permission checks. If permissions are too open, the server will reject
the authentication attempt for security reasons:
- The
.sshdirectory must be owned by the user and set to permissions700(rwx------). - The
authorized_keysfile must be owned by the user and set to permissions600(rw-------) or644(rw-r--r--).
Primary Benefits
- Enhanced Security: Public-key authentication is virtually immune to brute-force password guessing attacks.
- Automation: Scripts, configuration management tools (like Ansible), and CI/CD pipelines rely on this file to interact with servers without human interaction.
- Granular Access Management: System administrators can grant access to multiple users by adding their respective public keys, and immediately revoke access simply by deleting a specific line from the file.