scp file to server with user different than ssh login











up vote
1
down vote

favorite












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:



[corp@server.local ~]$ 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 corp@server.local/tmp/
$ ssh copr@server.local
Last login: Thu Apr 12 18:05:41 2018 from 192.168.87.34

[corp@server.local ~]$ sudo chown alice:alice /tmp/somefile.jar
[corp@server.local ~]$ 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?










share|improve this question
























  • If you can't connect as alice to the server, then yes, you found the shortest way to do that
    – Félicien
    Apr 13 at 8:45










  • @Félicien - Thank you. I cannot login as alice user
    – Loom
    Apr 13 at 8:46















up vote
1
down vote

favorite












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:



[corp@server.local ~]$ 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 corp@server.local/tmp/
$ ssh copr@server.local
Last login: Thu Apr 12 18:05:41 2018 from 192.168.87.34

[corp@server.local ~]$ sudo chown alice:alice /tmp/somefile.jar
[corp@server.local ~]$ 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?










share|improve this question
























  • If you can't connect as alice to the server, then yes, you found the shortest way to do that
    – Félicien
    Apr 13 at 8:45










  • @Félicien - Thank you. I cannot login as alice user
    – Loom
    Apr 13 at 8:46













up vote
1
down vote

favorite









up vote
1
down vote

favorite











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:



[corp@server.local ~]$ 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 corp@server.local/tmp/
$ ssh copr@server.local
Last login: Thu Apr 12 18:05:41 2018 from 192.168.87.34

[corp@server.local ~]$ sudo chown alice:alice /tmp/somefile.jar
[corp@server.local ~]$ 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?










share|improve this question















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:



[corp@server.local ~]$ 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 corp@server.local/tmp/
$ ssh copr@server.local
Last login: Thu Apr 12 18:05:41 2018 from 192.168.87.34

[corp@server.local ~]$ sudo chown alice:alice /tmp/somefile.jar
[corp@server.local ~]$ 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?







scp file-copy chown






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 5 at 23:30









Jeff Schaller

37.4k1052121




37.4k1052121










asked Apr 13 at 8:35









Loom

1,03021928




1,03021928












  • If you can't connect as alice to the server, then yes, you found the shortest way to do that
    – Félicien
    Apr 13 at 8:45










  • @Félicien - Thank you. I cannot login as alice user
    – Loom
    Apr 13 at 8:46


















  • If you can't connect as alice to the server, then yes, you found the shortest way to do that
    – Félicien
    Apr 13 at 8:45










  • @Félicien - Thank you. I cannot login as alice user
    – Loom
    Apr 13 at 8:46
















If you can't connect as alice to the server, then yes, you found the shortest way to do that
– Félicien
Apr 13 at 8:45




If you can't connect as alice to the server, then yes, you found the shortest way to do that
– Félicien
Apr 13 at 8:45












@Félicien - Thank you. I cannot login as alice user
– Loom
Apr 13 at 8:46




@Félicien - Thank you. I cannot login as alice user
– Loom
Apr 13 at 8:46










2 Answers
2






active

oldest

votes

















up vote
2
down vote













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 copr@server.local 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.






share|improve this answer




























    up vote
    0
    down vote













    That is most likely the only way to do that.






    share|improve this answer





















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "106"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f437471%2fscp-file-to-server-with-user-different-than-ssh-login%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      2
      down vote













      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 copr@server.local 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.






      share|improve this answer

























        up vote
        2
        down vote













        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 copr@server.local 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.






        share|improve this answer























          up vote
          2
          down vote










          up vote
          2
          down vote









          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 copr@server.local 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.






          share|improve this answer












          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 copr@server.local 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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 14 at 19:01









          meuh

          31.2k11754




          31.2k11754
























              up vote
              0
              down vote













              That is most likely the only way to do that.






              share|improve this answer

























                up vote
                0
                down vote













                That is most likely the only way to do that.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  That is most likely the only way to do that.






                  share|improve this answer












                  That is most likely the only way to do that.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 13 at 8:46









                  Buddika

                  1324




                  1324






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f437471%2fscp-file-to-server-with-user-different-than-ssh-login%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      サソリ

                      広島県道265号伴広島線

                      Accessing regular linux commands in Huawei's Dopra Linux