I have file /home/user1/file.txt which I want to copy to /home/user2/file.txt. Neither user has any permission to other users home directory, but both user2 has permission to su user1. I administrate both accounts. How do I copy the file to user2 (with his permissions) as user1, when I know both users credentials?

  • What do you mean by "copy the file to user2 (with his permissions) as user1"? Should the copied file have have user1's or user2's permissions? – AFH Feb 15 '18 at 11:28
  • user2's permissions, but the file is copied by user1 – Tuomas Toivonen Feb 15 '18 at 17:17

I see two solutions :

Copy the file as root and then change the permission to user2

sudo cp /home/user1/file.txt /home/user2/
sudo chown user2:user2 /home/user2/file.txt

Or, copy the file from user1 to a folder where user 1 and user2 have permissions and then move it to /home/user2 with user2

user1 :

cp ~/file.txt /tmp

user2 :

mv /tmp/file.txt ~/file.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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