Ssh – set umask for sshfs-mounted filesystem

filesystemsmountpermissionssshfsumask

I have a remote sshfs filesystem mounted on /mnt/data. Following is the relevant line in /etc/fstab:

www-data@192.168.1.10:/var/www/ /mnt/data       fuse.sshfs   rw,noauto,nodev,nosuid,noexec,_netdev,allow_other,default_permissions,uid=martin,gid=martin    0   0

The files in /var/www/ on the remote system are owned by user www-data, but I am using uid=martin,gid=martin to map the ownership on the mounted filesystem to uid 1000.

When I cd to /mnt/data/ as martin, I have the correct file permissions/ownership, but I need to change the umask.

On the remote filesytem, the user www-data has umask 0027. On my local filesystem, the user martin has umask 0077. I want to keep the umask 0077 on my local files, but use 0027 on the sshfs mounted files (ie all files in /mnt/data/).

Is this even possible ?

I have tried setting acl permissions on the whole directory on the remote filesystem:

setfacl -d -m g::rx  /var/www/
setfacl -d -m o::--- /var/www/

but this has no effect on the sshfs mounted share.

Best Answer

sshfs is using sftp under the hood and the umask for creation new files is handled by the remote sftp-server. You can set umask as an argument to the sftp-server in /etc/ssh/sshd_config on the server, such as

Subsystem sftp /usr/lib/openssh/sftp-server -u 027     # Debian/Ubuntu

or

Subsystem sftp /usr/libexec/openssh/sftp-server -u 027 # RHEL/Fedora

or

Subsystem sftp /usr/lib/ssh/sftp-server -u 027         # Arch

The umask settings and extended ACL are not transferred through the SFTP protocol as implemented by openssh. Also note that there is no "umask on files", but umask is always associated with running process creating the files.

Related Question