System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

my umask doesnt work when doing scp

 
Jhingan
Occasional Advisor

my umask doesnt work when doing scp

When i create teh files locallay on teh system then the umask works perfectly fine. However when i scp the files from a differnt server then the files doesnt stick to the default permission i have set on destination.

i have already tried numerous workaround like:

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

http://www.kernel.org/pub/linux/libs/pam/Linux-PAM-html/sag-pam_umask.html

here is the example

Source
[ajhingan@station1 ajhingan]$ umask
0027

[ajhingan@station1 ajhingan]$ ls –ltr abc
-rw-r----- 1 ajhingan ajhingan 0 Jun 25 07:13 abc

Destination

[ajhingan@station2 ~]$ scp ajhingan@station1:/home/ajhingan/abc .

[ajhingan@station2 ~]$ umask
0002

[ajhingan@station2 ~]$ ls -ltr
total 0
-rw-r----- 1 ajhingan ajhingan 0 Jun 25 07:14 abc

Any help will really be greatly appreciable
10 REPLIES
Ivan Ferreira
Honored Contributor

Re: my umask doesnt work when doing scp

Your problem is that scp always tries to mantain the permissions of the file. In this case, you will always get the permissions of the original file and your local umask won't take effect. This is a scp "feature" or limitation in your case.

You could try something like:

ssh ajhingan@station1 dd if=/home/ajhingan/abc | dd of=abc

This will copy the file to the local host and the umask will be applied to the file permissions.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Wilfred Chau_1
Respected Contributor

Re: my umask doesnt work when doing scp

did you try the -p flag?

scp -p ajhingan@station1:/home/ajhingan/abc .

it should perserve the permission set on station1.
Jhingan
Occasional Advisor

Re: my umask doesnt work when doing scp

Thanks Ivan & Wilfred for your solutions but unfortunately none of thm going to help me in my case as the source is not defined. The file can come from any one of the thousands of servers but the good part is that the user will remain the same. So the only thing left is to make changes at the destination where we can mandate a umask of 0002 for that particular user. Any thoughts?
Jhingan
Occasional Advisor

Re: my umask doesnt work when doing scp

does anyone has a solution to my problem??
Jhingan
Occasional Advisor

Re: my umask doesnt work when doing scp

I am trying to use
sftpfilecontrol (http://sftpfilecontrol.sourceforge.net/) to manage the
umask on a per-user basis. However, I can't get it to work too
Steven Schweda
Honored Contributor

Re: my umask doesnt work when doing scp

> I am trying to use [...]

Not a useful description of what you did.

> [...] I can't get it to work too

Not a useful description of what happened
when you did it.

Did you notice that "scp" and "sftp" are
spelled differently?
Jhingan
Occasional Advisor

Re: my umask doesnt work when doing scp

Sorry if i wasnt too much descriptive in my previous post. This is what i tried

I integrated a sftpfilecontrol patch v1.3 with my openssh 5.1p1 and build an rpm for that. I can now see my sshd_config file is showing me the Umask changed option.

[root@station1 SPECS]# nc localhost 22
SSH-2.0-OpenSSH_5.1p1+sftpfilecontrol-v1.3

[root@station1 ~]# cat /etc/ssh/sshd_config | grep -i sftp
SftpUmask 0002
Subsystem sftp /usr/libexec/openssh/sftp-server

[root@station1 ~]# uname -i
i386

[root@station1 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)


However i am still confused if whatever i did was to make the changes for just SFTp and not SCP? Are sftp and scp work differently? If yes then what patch should i imply for the changing UMASk for scp transactions?
Steven Schweda
Honored Contributor

Re: my umask doesnt work when doing scp

> [...] Are sftp and scp work differently?
> [...]

They're spelled differently for a reason.

> [...] If yes then what patch should i imply
> [...]

I have no idea. I didn't even know about the
patch for SFTP.

Have you considered using SFTP instead of
SCP?
Jhingan
Occasional Advisor

Re: my umask doesnt work when doing scp

So i given a try trasnferring files using sftp. For sftp trasnactions the umask works fine but for scp the issue remains the same. Can anyone on this forum help me with setting up a defalu permission on scp transactions please?
Steven E. Protter
Exalted Contributor

Re: my umask doesnt work when doing scp

Shalom,

Welcome to ITRC.

Yes sftp and scp work differently. It is not totally unreasonable for one to expect openssh, which includes ssh,sftp and scp to work consistently. By default, they use the user profile, including umask.

But in this case, probably due to security concerns they do not work the same way. The other Steven may be trying to make this point to you.

To impact the scp permissions the way you have sftp permissions, a new rpm or software and sshd_config configuration will likely be required.

To find out about scp umask, I recommend reading the following search:
http://www.google.com/search?q=scp+umask+for+openssh&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

I read a few of the links and found no solution.

Your profile....
I have assigned points to 0 of 4 responses to my questions.

May want to do something about that.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com