Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

The sftp-server will create the new file with the default umask of the user. This can be overridden with the -u umask option to sftp-server

SFTP-SERVER(8)
     -u umask
             Sets an explicit umask(2) to be applied to newly-created files 
             and directories, instead of the user's default mask.

The client (OpenSSH sftp) can choose to preserve local permission by using the -p option, which will send the file then fchmod it appropriately.

SFTP(1) 
     -p      Preserves modification times, access times, and modes from the 
             original files transferred.

If you're strictly asking how to set a mandatory file mode with the sftp client; you can't (at least with openssh sftp-client). You will have to send a chmod after sending the file.

share|improve this answer
    
This is not about sftp-server umask setting. I checked the OpenSSH SFTP client source code and at even if -p option is not specified the sftp client will still preserve file modes. koders.com/c/…. So when using OpenSSH sftp client the file modes are always preserved. –  Adi Roiban Jun 27 '11 at 18:21
1  
How does the OpenSSH sftp client source even matter, since you are using WinSCP/Filezilla/psftp from a Windows box to connect? OpenSSH !=Putty. Since it is a Windows box, what do you expect the permissions to be, if the permissions where preserved? Are you somehow expecting the server to magically guess what the permissions should be if the client doesn't support permissions? –  Zoredache Jun 27 '11 at 18:43
1  
@Adi - I'm not sure where you're seeing that. The only call to do_fsetstat is on line 1108, under if (pflag) (the -p option). A simple put does not modify the remote file mode after writing it. It will call open with the original file's mode_t, which will have the umask xor'ed from it on the server side. –  JimB Jun 27 '11 at 18:46
2  
@Adi - yes, that's exactly what I'm saying!? The sftp-server will call open with the requested mode, which gets modified by the umask. If there is no umask, the mode is copied in full. The options to possibly change the mode of the file are: set the user's umask on the server; set the sftp-server umask with -u; call chmod directly; or set permissions locally, and use -p in the client. You're looking at the source yourself, there's no "put-and-set-attributes" style command in the protocol. –  JimB Jun 27 '11 at 19:27
2  
@Adi, SSH_FXP_OPEN is the same thing we were discussing earlier. Notice the wording, "desired-access"! If the file doesn't exist, the server will call open(name, flags, mode) with O_CREAT, which doesn't guarantee mode because the umask will always be applied via mode & ~umask, (don't no why I typed xor earlier, but I can't edit it). The only time (f)chmod is called on the file (you can watch this with strace), is if you use the -p flag, or call chmod explicitly. Putty sftp may very well call chmod on it's own due to the impedance mismatch of windows->unix attributes –  JimB Jun 28 '11 at 13:51

I believe that the sftp-server will use the user's profile's default umask unless it has been started with an explicit umask (man 8 sftp-server for details).

share|improve this answer
    
Thanks for you answer. This question is not about umask, but the default file permission requested by the sftp client. Each time the OpenSSH sftp client puts a file on the server it request an chmod of 640. –  Adi Roiban Jun 24 '11 at 8:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.