SFTP Server: Force Two Different Umask Values on Different Directories
If you are using an SFTP server and want to have different umask values for different directories, this article will guide you through the process. Umask is a permission mask that determines the default permissions for newly created files and directories. By default, the umask value is set globally for the entire server, but with a little configuration, you can enforce different umask values on specific directories.
To achieve this, you will need to modify the server's configuration file. The specific steps may vary depending on the SFTP server software you are using, but the general concept remains the same.
Here are the steps to force two different umask values on different directories:
- Locate the configuration file for your SFTP server. This file is usually named something like
sshd_configorsftp-server.conf. - Open the configuration file using a text editor.
- Search for a section that defines the settings for the SFTP server.
- Within that section, look for a line that starts with
Subsystem sftp. This line specifies the command that is executed when an SFTP session is initiated. - Add the
-uoption followed by the desired umask value to the end of the line. For example, if you want to set a umask value of 022, the line would look like this:Subsystem sftp /usr/lib/openssh/sftp-server -u 022. - Save the configuration file and exit the text editor.
- Restart the SFTP server for the changes to take effect. The specific command to restart the server may vary depending on your operating system. For example, on Linux, you can use the command
sudo service ssh restart.
Now that you have set a global umask value for the entire server, you can proceed to set different umask values for specific directories.
Here's how to enforce different umask values on specific directories:
- Identify the directories for which you want to set different umask values.
- For each directory, create a new configuration block in the SFTP server's configuration file.
- Within each configuration block, specify the
ForceCommanddirective followed by the desired umask value. For example, if you want to set a umask value of 077 for a directory called/sensitive, the configuration block would look like this:Match User your_username ForceCommand /bin/sh -c 'umask 077; /usr/lib/openssh/sftp-server' - Save the configuration file and exit the text editor.
- Restart the SFTP server for the changes to take effect.
That's it! You have successfully enforced different umask values on different directories in your SFTP server. Now, newly created files and directories in the specified directories will have the desired permissions according to the umask values you have set.
References
| Source | Description |
|---|---|
| SSH.com | SSH Umask Explained |
| OpenBSD Manual | SFTP-Server Manual |