0

I am user_a and I have a password for user_b, so I can use su user_b to do things as user_b.

I want to copy a file from user_a to user_b.

I don't want other users besides user_a and user_b to see the file, and I don't have root on the machine. So the usual trick of moving the file to /tmp is not acceptable.

1 Answers1

1

You can use back to back tar to do the copy. For example

 tar cf - file1 file2 dir1/file3 | su user_b tar -C ~user_b/somewhere -xf -

This will create ~user_b/somewhere/file1 as a copy of file1. ~user_b/somewhere has to exist first. There are some limitations on the tar format, but you are unlikely to hit them.

If it is just a single file then

 su - user_b bash -c 'cat > ~user_b/file1' < file1

followed by adjusting the permissions might be less trouble.

icarus
  • 17,920
  • I got a "permission denied" with the cat example, but the ln example worked for me from this answer: https://unix.stackexchange.com/a/185826/57734 – Alex Shroyer Feb 04 '20 at 15:02