Copying file from other user's directory with '-p' switch should reserve the permission as per the man page.
I am copying /etc/passwd to my home directory with -p switch but the permissions aren't preserved as follows:-
ijoin@stream:~$ ls -l /etc/passwd
-rw-r--r-- 1 root root 1813 Sep 25 08:58 /etc/passwd
ijoin@stream:~$ cp --preserve /etc/passwd .
ijoin@stream:~$ ls -l passwd
-rw-r--r-- 1 ijoin ijoin 1813 Sep 25 08:58 passwd
I am doing something wrong?
You're logged in as
ijohn
and copying a file owned byroot
.cp
command can not work around Linux's security machinery - your user is not allowed to create files owned byroot
or change ownersip of files toroot
. Doing so would be a security problem.If you need to copy files owned by other users, do so using
sudo
:Here's a good explanation I found on linuxquestions.org: