Where are SSH Authorized Keys Stored in Ubuntu
This article explains the exact file location where authorized SSH public keys are stored on a remote Ubuntu Linux server. It covers the directory path, how the file functions for user authentication, and the essential file permissions required to keep the connection secure.
On an Ubuntu Linux server, the authorized SSH public keys for a
specific user are stored in a file named
authorized_keys.
This file is located within a hidden directory called
.ssh inside the user’s home directory. The absolute path to
the file is:
/home/username/.ssh/authorized_keys
For the root user, the path is:
/root/.ssh/authorized_keys
How the Authorized Keys File Works
The authorized_keys file acts as a database of trusted
public keys allowed to log into that specific user account. Each public
key is stored as a single, continuous line of text. When you attempt to
connect to the Ubuntu server via SSH using a private key, the SSH daemon
(sshd) compares your private key against the corresponding
public keys listed in this file. If a match is found, access is
granted.
Required Directory and File Permissions
For security reasons, the SSH daemon will ignore the
authorized_keys file if its permissions, or the permissions
of its parent directory, are too open. To ensure secure and successful
connections, set the following permissions:
The
.sshdirectory must be private to the owner. Set its permissions to700:chmod 700 ~/.sshThe
authorized_keysfile must only be readable and writable by the owner. Set its permissions to600:chmod 600 ~/.ssh/authorized_keys
Both the directory and the file must also be owned by the user you
are trying to log in as, which can be configured using the
chown command if necessary.