1

I need to copy file somefile.jar from local computer (cygwin) to remote server.local. I have an ssh login corp to server.local that a sudoer on server.local. I need to place the file to folder /opt/alice/libs/ owned by another user:

[[email protected] ~]$ ls -ld /opt/alice/libs
drwxr-xr-x 2 alice alice 12288 Apr 13 11:09 /opt/alice/libs

I cannot direct upload file to chosen directory because of insufficient rights. So, my way to copy has few steps with /tmp/ on server.local

$ scp ./somefile.jar [email protected]/tmp/
$ ssh [email protected]
Last login: Thu Apr 12 18:05:41 2018 from 192.168.87.34

[[email protected] ~]$ sudo chown alice:alice /tmp/somefile.jar
[[email protected] ~]$ sudo -u alice mv /tmp/somefile.jar /opt/alice/libs/

Is there a shorter way to perform the upload?


If a tool does not exist to achieve my purposes, maybe it is possible to make a *.sh script that include all of these operations?

2
  • If you can't connect as alice to the server, then yes, you found the shortest way to do that
    – Félicien
    Commented Apr 13, 2018 at 8:45
  • @Félicien - Thank you. I cannot login as alice user
    – Loom
    Commented Apr 13, 2018 at 8:46

2 Answers 2

2

If you want to do a simple script, assuming your sudo does not need a password, you could pipe the data across:

tar cf - ./somefile.jar | 
ssh -t [email protected] sudo -u alice tar xf - -C /opt/alice/libs/

The -C changes directory before extracting the file. If your tar does not have this, add an explicit cd /opt/alice/libs/ first.

0

That is most likely the only way to do that.

0

You must log in to answer this question.

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