I have been trying to figure out what is wrong with the file rights. When I am uploading files using FileZilla all the files get rights -rw-r–r–. I would want them to have -rwxr-xr-x. I have tried using umask to fix the rights but something is wrong. I have read that you could change the rights with umask like this for example:
In /etc/ssh/sshd_config, change the following:
Subsystem sftp /usr/lib/openssh/sftp-server -u 002
With this change I am getting files with -rw-rw-r–. As far as I know 0 should give all rights? But I am getting rw only.
Whats wrong? I am using Debian.
Best Answer
If an SFTP client does not specify permissions for uploaded files, the OpenSSH SFTP server assigns 0666 permissions to newly created files (minus the umask 0002 makes the 0664).
This is hard-coded, you cannot change it. See the
process_open()
function in thesftp-server.c
of OpenSSH. And even, if this was not specified explicitly, the 0666 is still the *nix default for files, you cannot just change this with umask (that's true in general, not just for OpenSSH).See also Does OpenSSH SFTP server use umask or preserve client side permissions after put command (chrooted environment)?
Note that your umask is actually wrong. If you want 0644, use umask 0022, not 0002.
The FileZilla never specifies permissions for uploaded files. What results in the behavior you are experiencing.
To achieve your desired permissions:
With FileZilla you can change the file permissions only manually, after the upload, using File permissions command from a remote file context menu.
Use an SFTP client that allows specifying the permissions for the uploaded files.
For example WinSCP allows that.
See https://winscp.net/eng/docs/ui_transfer_custom
(I'm the author of WinSCP)