This article provides a guide for setting .ssh file and directory permissions for a user on Linux-based server.
Setting .ssh File and Directory Permissions
To ensure your SSH setup is secure, setting .ssh file and directory permissions to the appropriate values is critical for SSH-related files and directories. Below is a table summarizing the permissions for key files and directories:
Item | Sample Path | Numeric | Textual |
---|---|---|---|
SSH folder | ~/.ssh |
700 |
drwx------ |
Public key | ~/.ssh/id_rsa.pub |
644 |
-rw-r--r-- |
Private key | ~/.ssh/id_rsa |
600 |
-rw------- |
Authorized keys | ~/.ssh/authorized_keys |
600 |
-rw------- |
Home folder | ~ |
755 |
drwxr-xr-x |
Explanation of Permissions:
- SSH Folder (
~/.ssh
): This folder must have700
permissions, allowing read, write, and execute access only for the owner. - Public Key (
id_rsa.pub
): This file can be publicly readable, so644
permissions are appropriate. - Private Key (
id_rsa
): The private key must be strictly protected, so600
ensures only the owner can read and write to it. - Authorized Keys (
authorized_keys
): This file contains the public keys authorized for SSH access. It must have600
permissions to ensure it is only readable and writable by the owner. - Home Folder (
~
): Ensure your home folder has755
permissions or less, so it is not writable by others.
To set these permissions, use the following commands:
chmod 700 ~/.ssh
chmod 644 ~/.ssh/id_rsa.pub
chmod 600 ~/.ssh/id_rsa
chmod 600 ~/.ssh/authorized_keys
chmod 755 ~
These permissions help secure your SSH access by limiting file access to only the necessary users.
Conclusion
You now know about setting .ssh file and directory permissions for users on Linux-based servers.