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

We have an Ubuntu 10.04 server. How can I set it so that new files created (or copied) over SFTP or SSH have g+rw and g+rwx permissions (where appropriate)?

I'm also using setgid (chmod g+s) so that they inherit the proper group owner.

share|improve this question

2 Answers 2

up vote 7 down vote accepted

In /etc/ssh/sshd_config, change the following:

Subsystem sftp /usr/lib/openssh/sftp-server

to:

Subsystem sftp /bin/sh -c 'umask 0002; exec /usr/libexec/openssh/sftp-server'

Soure: http://jeff.robbins.ws/articles/setting-the-umask-for-sftp-transactions

share|improve this answer
1  
It's better to put an exec before the final /usr/.../sftp-server, so that you won't have useless sh processes lying around. –  grawity Jun 13 '10 at 20:32
    
Also, an umask is just a number; 0002 can be written shorter as 02. –  grawity Jun 13 '10 at 20:33
    
I thought umask was an octal, but thanks for the exec part. –  wag2639 Jun 16 '10 at 15:38
2  
Yes, umasks are octal. That doesn't mean you need three leading zeroes - one is enough. (In fact, the umask command doesn't need any leading zeroes, it always reads the argument as an octal number.) ... But on the second thought, maybe 0002 is clearer to understand. –  grawity Jun 19 '10 at 20:52

In /etc/ssh/sshd_config, you can pass a flag and value in (-u 0002) like the following to set the umask value:

Subsystem sftp /usr/lib/openssh/sftp-server -u 0002

Append the -u 0002 to the existing Subsystem sftp line of the configuration file.

Afterwards, you will need to restart ssh for the changes to take effect:

service ssh restart
share|improve this answer
    
This only applies to newer versions of OpenSSH, but should be the preferred solution where possible. –  Andrew B Jan 12 '13 at 6:27

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.