Setting .ssh File and Directory Permissions


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 have 700 permissions, allowing read, write, and execute access only for the owner.
  • Public Key (id_rsa.pub): This file can be publicly readable, so 644 permissions are appropriate.
  • Private Key (id_rsa): The private key must be strictly protected, so 600 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 have 600 permissions to ensure it is only readable and writable by the owner.
  • Home Folder (~): Ensure your home folder has 755 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.

  • ssh keys, ssh commands, ssh, file permissions, chmod, security
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

View Server PHP Environment with phpinfo.php

The phpinfo() function outputs a huge amount of information about the system you're using, such...

How to Create Sudo User on CentOS

This article provides step-by-step setup guide for adding Sudo user to CentOS system. The sudo...

How to Use Sudo

This article provides a guide to using a Sudo user on CentOS server. From the command line,...

Set Server Time Zones with Timedatectl

This article provides a guide to setting the server time and server time zone settings using...

508 Resource Limit is Reached

If your website is on a cPanel hosting account, you may have noticed the following error message:...