How to Set SFTP umask in Linux

Deepak Prasad
Tested on Red Hat Enterprise Linux 10.2 (Coughlan)
Package openssh-server 9.9p1-25.el10_2
openssh-clients 9.9p1-25.el10_2
Applies to RHEL, Rocky Linux, AlmaLinux, Fedora, Ubuntu, and Debian with OpenSSH internal-sftp or sftp-server
Privilege sudo or root to edit /etc/ssh/sshd_config and reload sshd
Scope Set SFTP umask globally or with Match User / Match Group, validate sshd_config, and verify upload modes. Does not cover SFTP chroot setup or SSH hardening beyond umask.
Related guides umask on Linux
Restrict SFTP to a directory
OpenSSH authentication in sshd_config
chmod recursive examples
Add user to group in Linux

umask controls which permission bits are removed when a new file or directory is created. For interactive shells, you set it in /etc/profile, .bashrc, or similar files — the umask on Linux guide covers that calculation. SFTP is different: OpenSSH handles uploads with internal-sftp or sftp-server, not your login shell, so a user's .bashrc umask is not a reliable way to control SFTP file modes.


Quick answer

Goal Config or command
Check current SFTP subsystem sshd -T | grep -i '^subsystem'
Global SFTP umask Subsystem sftp internal-sftp -u 0027 in /etc/ssh/sshd_config
Per-group SFTP umask Match Group sftpusers with ForceCommand internal-sftp -u 0027
Per-user SFTP umask Match User deploy with ForceCommand internal-sftp -u 0022
Validate before reload sudo sshd -t
Reload sshd on RHEL sudo systemctl reload sshd
Verify uploaded mode stat -c '%a %n' file

For most SFTP-only accounts, a Match Group block with ForceCommand internal-sftp -u is cleaner than changing the global subsystem line.


How SFTP umask changes permissions

If the SFTP client requests these creation modes, umask 0027 removes the listed bits:

Object Requested mode With umask 0027
File 0666 0640
Directory 0777 0750

The mode requested by an SFTP client can vary, especially when the client is asked to preserve permissions. The server-side -u setting applies its umask to newly created files and directories, so it can remove permission bits but cannot add missing ones.

The rule that trips up SFTP admins: umask removes permission bits; it does not add missing bits. Umask 0027 does not force new files to 0640. If the client requests 0600, the result remains 0600.


Check the current SFTP subsystem

Before editing sshd_config, see how SFTP is wired today:

bash
sshd -T | grep -i '^subsystem'

Sample output:

output
subsystem sftp /usr/libexec/openssh/sftp-server

On RHEL and Fedora the binary lives under /usr/libexec/openssh/. On Debian and Ubuntu it is usually /usr/lib/openssh/sftp-server. Add -u through internal-sftp in the subsystem line or in a Match block with ForceCommand.


Set SFTP umask globally

Use a global subsystem line only when every SFTP user should share the same umask. Edit /etc/ssh/sshd_config:

text
Subsystem sftp internal-sftp -u 0027

That tells OpenSSH to run internal-sftp with umask 0027 for all SFTP sessions. A global change affects every SFTP user on the host, so prefer Match blocks when only some accounts need a custom umask.


Set SFTP umask for a group or user

ForceCommand internal-sftp makes matching accounts SFTP-only; use this form when that is intended. If users still need normal SSH shell access, do not add ForceCommand just to set an SFTP umask.

To give members of sftpusers umask 0027 on SFTP sessions:

text
Subsystem sftp internal-sftp

Match Group sftpusers
    ForceCommand internal-sftp -u 0027

When one account needs a different umask, use Match User:

text
Subsystem sftp internal-sftp

Match User deploy
    ForceCommand internal-sftp -u 0022

Only deploy gets umask 0022 on SFTP sessions. Other users keep the default subsystem behavior. If these accounts also need chroot or forwarding restrictions, configure those separately — see restrict SFTP to a directory.


Validate and reload sshd

Always syntax-check sshd_config before reload or restart:

bash
sudo sshd -t

No output and exit status 0 mean the file parsed cleanly. On RHEL, Rocky Linux, and AlmaLinux, reload the running daemon:

bash
sudo systemctl reload sshd

On Ubuntu and Debian the unit is often named ssh instead of sshd:

bash
sudo systemctl reload ssh

Keep an existing SSH session open while testing a reload.


Verify uploaded permissions

Upload a normal test file over SFTP after you set -u 0027:

bash
sftp user@server

At the sftp> prompt:

text
sftp> put test.txt

On the server, check the mode of the uploaded file:

bash
stat -c '%a %n' /upload/path/test.txt

Note the resulting mode and compare it with the mode requested or preserved by your SFTP client. Replace /upload/path/ with the directory where that user's SFTP session can write.

To show that umask cannot add permission bits, upload two small local files with different source modes and compare the results. With the OpenSSH sftp client used in this test and umask 0027 configured, a 0644 source was created remotely as 0640, while a 0600 source stayed 0600. Your client may request different modes, so check with stat rather than assuming a fixed result.

The important rule is that the server-side umask can remove permission bits, but cannot add bits the client did not request. If uploads stay at mode 600, compare the source mode with the remote file before assuming -u 0027 is ignored.


Troubleshooting

Symptom Likely cause Fix
Uploaded file stays 600 Client requested 0600; umask cannot add permissions Compare source and upload modes with stat
.bashrc umask ignored SFTP is not an interactive shell session Set internal-sftp -u or sftp-server -u in sshd_config
Group umask does not apply User did not match the Match Group block Run id username; check with sshd -T -C user=...,host=...,addr=...
Reload fails Syntax error in sshd_config Run sudo sshd -t before systemctl reload
Unexpected owner or group Primary group or directory setgid differs Check id, directory ownership, ACLs, and setgid on the upload path

When umask alone is not enough — for example you need forced group ownership or default ACLs on every new file — use setgid directories or setfacl -d rather than expecting umask to add permissions.


References


Summary

SFTP upload permissions are controlled in OpenSSH, not in .bashrc. Set umask with internal-sftp -u UMASK inside sshd_config. A global Subsystem sftp internal-sftp -u 0027 line applies one umask to every SFTP user; Match Group or Match User with ForceCommand internal-sftp -u limits the change to selected accounts.

Umask 0027 does not force files to 0640. It removes permission bits from the mode the SFTP client requests. If the client requests 0600, the result remains 0600. Before reloading production sshd, run sshd -t, then confirm remote modes with stat -c '%a %n' file.


Frequently Asked Questions

1. How do I set umask for SFTP in Linux?

For OpenSSH internal-sftp, set ForceCommand internal-sftp -u 0027 inside a Match User or Match Group block in sshd_config. For a global SFTP subsystem, use Subsystem sftp internal-sftp -u 0027.

2. Does .bashrc umask apply to SFTP uploads?

Usually no. Non-interactive SFTP sessions handled by internal-sftp or sftp-server do not run shell startup files the way an interactive login does, so .bashrc umask is not a reliable SFTP control.

3. What permissions does SFTP umask 0027 create?

If the SFTP client requests mode 0666 for a new file, umask 0027 results in 0640. If it requests 0777 for a directory, the result is 0750. The actual mode requested by the client can vary.

4. Why did my SFTP file stay 600 after setting umask 0027?

umask can remove permissions from the mode requested by the client, but it cannot add permissions that were not requested. If the client requests 0600, umask 0027 still leaves the file as 0600.

5. Should I use Subsystem sftp internal-sftp -u or ForceCommand internal-sftp -u?

Use Subsystem sftp internal-sftp -u only when the same umask should apply to every SFTP user. Use Match User or Match Group with ForceCommand internal-sftp -u when only selected SFTP users or groups need that umask.

6. Do I need to restart sshd after changing SFTP umask?

Validate the config first with sshd -t, then reload or restart sshd depending on your distribution. Reload is usually safer for active SSH sessions than a full restart.
Omer Cakmak

Linux Administrator

Highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware.

  • Debian
  • Ubuntu
  • Linux
  • Red Hat Enterprise Linux
  • Shell Script
  • System Administration