0

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?

2
  • 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
    Commented Feb 15, 2018 at 11:28
  • user2's permissions, but the file is copied by user1 Commented Feb 15, 2018 at 17:17

1 Answer 1

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .