OpenSSH – Specify File Permission When Using SFTP Command

file-permissionssftpssh

I am using various SFTP clients for uploading files to an SFTP server and I have a problem with default permission used when putting files.

When requesting to put a file, SFTP client like WinSCP or Filezilla will send the SSH_OPEN command without requesting any explicit file permission.

On the other side, it looks like the OpenSSH sftp command on Linux (Red Hat and Ubuntu) is pending the SSH_OPEN command together with the '640' mode.

How can I configure the OpenSSH command to not explictly set the file mode or how can I configure it to send a mode, other than 640?

Many thanks!


Update:

I checked the OpenSSH sftp client source code and it looks like OpenSSH sftp will always tries to preserve file mode even if -P is not set:
http://www.koders.com/c/fidD3B20680F615B33ACCB42398FAAFEE1C007DF942.aspx?s=rsa#L986

To solve this problem I used Putty SFTP client.

Best Answer

If an SFTP client does not specify permissions for uploaded files, the OpenSSH SFTP server assigns 0664 permissions to newly created files. That's for the default umask 0002, which you can change using the -u switch as the answer by @JimB shows.


If an SFTP client specifies the permissions, OpenSSH server uses the specified permissions (the umask does not apply).

Overview of some popular SFTP clients: