Search code examples
linuxcopyremote-serveraccount

how to copy files to a shared account in remote linux server


We have a multiple user shared account in server, and every time I login in my own account in server through ssh and use sudo -u shared_account -i to login that account.

Now I want to copy some files to the shared account, and my current solution is:

  1. copy the files to my own account in server by scp command
  2. login to the server with my own account
  3. login the shared account
  4. copy the files in my own account to the folder of that shared account

Is there any way I can copy files directly from my local PC to the folder of shared account in the server?

OS of server is Linux, and my local PC is Mac.


Solution

  • You could send an archive stream via ssh and sudo.

    tar czf - file1 file2 file3 | ssh remote_system sudo -u shared_account tar xvzf -
    

    Your comment to this answer shows that you have to enter your password when running sudo. Unfortunately this wasn't mentioned in the question.

    If you can run programs that open a TCP port, e.g. netcat (nc) as the shared user you could combine this with tar (or cpio) to transfer files directly using the shared user's permissions and environment.