scp forces original access permissions when owner lacks write access

Brendan Moloney moloney.brendan at gmail.com
Wed Jul 7 11:28:20 EST 2010


Hello,

I am not sure if this is a bug or a feature...

When I use scp to copy a file to a filesystem which forces or masks
permissions on new files (in my case a samba share) the resulting
permissions depend on whether the owner had write access in the original
permissions. If the owner did have write access then the copied file ends up
with the permissions specified by the filesystem. If the owner did not have
write access then scp performs a chmod command after copying the data so
that the copied file ends up with the original permissions.

For example if I have mounted /samba_share which masks new file permissions
with 440 on the machine remote_machine:

$ touch testfile1 testfile2
$ chmod u-w testfile2
$ ls -l
-rw-r--r-- 1 someuser somegroup 0 Jul 6 18:04 testfile1
-r--r--r-- 1 someuser somegroup 0 Jul 6 18:04 testfile2
$ scp testfile* remote_machine:/samba_share
$ ssh remote_machine 'ls -l /samba_share'
-r--r----- 1 someuser somegroup 0 Jul 6 18:10 testfile1
-r--r--r-- 1 someuser somegroup 0 Jul 6 18:10 testfile2

It seems like the permissions should only be preserved if the -p flag is
used. However I am not sure if there is some other case where this is the
desired behavior.

Thanks for your time,
Brendan Moloney


More information about the openssh-unix-dev mailing list