Copy file using sudo access

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
1
down vote

favorite












How I can copy file or folder for other user.
New file or folder must have his name.



I have sudo access for cp command



USER1 ALL=(ALL) NOPASSWD: /bin/cp


I am trying following command:



USER1@ySERVERNAME:HOME_PATH$ sudo -i -u USER2 cp file1 file2


I got an error:



Sorry, user USER1 is not allowed to execute '/bin/bash -c cp file1 file2' as USER2 on SERVERNAME.


How can I solve it?










share|improve this question



























    up vote
    1
    down vote

    favorite












    How I can copy file or folder for other user.
    New file or folder must have his name.



    I have sudo access for cp command



    USER1 ALL=(ALL) NOPASSWD: /bin/cp


    I am trying following command:



    USER1@ySERVERNAME:HOME_PATH$ sudo -i -u USER2 cp file1 file2


    I got an error:



    Sorry, user USER1 is not allowed to execute '/bin/bash -c cp file1 file2' as USER2 on SERVERNAME.


    How can I solve it?










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      How I can copy file or folder for other user.
      New file or folder must have his name.



      I have sudo access for cp command



      USER1 ALL=(ALL) NOPASSWD: /bin/cp


      I am trying following command:



      USER1@ySERVERNAME:HOME_PATH$ sudo -i -u USER2 cp file1 file2


      I got an error:



      Sorry, user USER1 is not allowed to execute '/bin/bash -c cp file1 file2' as USER2 on SERVERNAME.


      How can I solve it?










      share|improve this question















      How I can copy file or folder for other user.
      New file or folder must have his name.



      I have sudo access for cp command



      USER1 ALL=(ALL) NOPASSWD: /bin/cp


      I am trying following command:



      USER1@ySERVERNAME:HOME_PATH$ sudo -i -u USER2 cp file1 file2


      I got an error:



      Sorry, user USER1 is not allowed to execute '/bin/bash -c cp file1 file2' as USER2 on SERVERNAME.


      How can I solve it?







      14.04 command-line sudo chown cp






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 21 at 9:44









      Yaron

      8,54271838




      8,54271838










      asked Feb 21 at 7:38









      Hayk Hovhannisyan

      61




      61




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          Solution:



          You should remove the -i from the sudo command:



          sudo -u USER2 cp file1 file2


          Explanation:



          The problem you are facing is that your sudo access is limited to /bin/cp and using sudo -i required extra sudo permissions which you don't have.



          As specify in the the error:




          Sorry, user USER1 is not allowed to execute '/bin/bash -c cp file1 file2' as USER2 on SERVERNAME.




          When using sudo -i -u USER2 cp The command you are running is /bin/bash -c cp which you don't have sudo permissions for. As you are limited to the command which you have sudo permission for: /bin/cp.



          More info: man sudo




           -i, --login
          Run the shell specified by the target user's password
          database entry as a login shell. This means that login-
          specific resource files such as .profile or .login will be
          read by the shell. If a command is specified, it is passed
          to the shell for execution via the shell's -c option. If no
          command is specified, an interactive shell is executed. sudo
          attempts to change to that user's home directory before
          running the shell. The command is run with an environment
          similar to the one a user would receive at log in. The
          Command environment section in the sudoers(5) manual
          documents how the -i option affects the environment in which
          a command is run when the sudoers policy is in use.






          share|improve this answer






















          • as I understand "file1" file need to have read permission, otherwise ti will give permission error: cp: cannot open ‘file1’ for reading: Permission denied
            – Hayk Hovhannisyan
            Feb 21 at 7:56











          • @HaykHovhannisyan - If I've solved your question, please accept my answer
            – Yaron
            Feb 21 at 8:01











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "89"
          ;
          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: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1008281%2fcopy-file-using-sudo-access%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote













          Solution:



          You should remove the -i from the sudo command:



          sudo -u USER2 cp file1 file2


          Explanation:



          The problem you are facing is that your sudo access is limited to /bin/cp and using sudo -i required extra sudo permissions which you don't have.



          As specify in the the error:




          Sorry, user USER1 is not allowed to execute '/bin/bash -c cp file1 file2' as USER2 on SERVERNAME.




          When using sudo -i -u USER2 cp The command you are running is /bin/bash -c cp which you don't have sudo permissions for. As you are limited to the command which you have sudo permission for: /bin/cp.



          More info: man sudo




           -i, --login
          Run the shell specified by the target user's password
          database entry as a login shell. This means that login-
          specific resource files such as .profile or .login will be
          read by the shell. If a command is specified, it is passed
          to the shell for execution via the shell's -c option. If no
          command is specified, an interactive shell is executed. sudo
          attempts to change to that user's home directory before
          running the shell. The command is run with an environment
          similar to the one a user would receive at log in. The
          Command environment section in the sudoers(5) manual
          documents how the -i option affects the environment in which
          a command is run when the sudoers policy is in use.






          share|improve this answer






















          • as I understand "file1" file need to have read permission, otherwise ti will give permission error: cp: cannot open ‘file1’ for reading: Permission denied
            – Hayk Hovhannisyan
            Feb 21 at 7:56











          • @HaykHovhannisyan - If I've solved your question, please accept my answer
            – Yaron
            Feb 21 at 8:01















          up vote
          2
          down vote













          Solution:



          You should remove the -i from the sudo command:



          sudo -u USER2 cp file1 file2


          Explanation:



          The problem you are facing is that your sudo access is limited to /bin/cp and using sudo -i required extra sudo permissions which you don't have.



          As specify in the the error:




          Sorry, user USER1 is not allowed to execute '/bin/bash -c cp file1 file2' as USER2 on SERVERNAME.




          When using sudo -i -u USER2 cp The command you are running is /bin/bash -c cp which you don't have sudo permissions for. As you are limited to the command which you have sudo permission for: /bin/cp.



          More info: man sudo




           -i, --login
          Run the shell specified by the target user's password
          database entry as a login shell. This means that login-
          specific resource files such as .profile or .login will be
          read by the shell. If a command is specified, it is passed
          to the shell for execution via the shell's -c option. If no
          command is specified, an interactive shell is executed. sudo
          attempts to change to that user's home directory before
          running the shell. The command is run with an environment
          similar to the one a user would receive at log in. The
          Command environment section in the sudoers(5) manual
          documents how the -i option affects the environment in which
          a command is run when the sudoers policy is in use.






          share|improve this answer






















          • as I understand "file1" file need to have read permission, otherwise ti will give permission error: cp: cannot open ‘file1’ for reading: Permission denied
            – Hayk Hovhannisyan
            Feb 21 at 7:56











          • @HaykHovhannisyan - If I've solved your question, please accept my answer
            – Yaron
            Feb 21 at 8:01













          up vote
          2
          down vote










          up vote
          2
          down vote









          Solution:



          You should remove the -i from the sudo command:



          sudo -u USER2 cp file1 file2


          Explanation:



          The problem you are facing is that your sudo access is limited to /bin/cp and using sudo -i required extra sudo permissions which you don't have.



          As specify in the the error:




          Sorry, user USER1 is not allowed to execute '/bin/bash -c cp file1 file2' as USER2 on SERVERNAME.




          When using sudo -i -u USER2 cp The command you are running is /bin/bash -c cp which you don't have sudo permissions for. As you are limited to the command which you have sudo permission for: /bin/cp.



          More info: man sudo




           -i, --login
          Run the shell specified by the target user's password
          database entry as a login shell. This means that login-
          specific resource files such as .profile or .login will be
          read by the shell. If a command is specified, it is passed
          to the shell for execution via the shell's -c option. If no
          command is specified, an interactive shell is executed. sudo
          attempts to change to that user's home directory before
          running the shell. The command is run with an environment
          similar to the one a user would receive at log in. The
          Command environment section in the sudoers(5) manual
          documents how the -i option affects the environment in which
          a command is run when the sudoers policy is in use.






          share|improve this answer














          Solution:



          You should remove the -i from the sudo command:



          sudo -u USER2 cp file1 file2


          Explanation:



          The problem you are facing is that your sudo access is limited to /bin/cp and using sudo -i required extra sudo permissions which you don't have.



          As specify in the the error:




          Sorry, user USER1 is not allowed to execute '/bin/bash -c cp file1 file2' as USER2 on SERVERNAME.




          When using sudo -i -u USER2 cp The command you are running is /bin/bash -c cp which you don't have sudo permissions for. As you are limited to the command which you have sudo permission for: /bin/cp.



          More info: man sudo




           -i, --login
          Run the shell specified by the target user's password
          database entry as a login shell. This means that login-
          specific resource files such as .profile or .login will be
          read by the shell. If a command is specified, it is passed
          to the shell for execution via the shell's -c option. If no
          command is specified, an interactive shell is executed. sudo
          attempts to change to that user's home directory before
          running the shell. The command is run with an environment
          similar to the one a user would receive at log in. The
          Command environment section in the sudoers(5) manual
          documents how the -i option affects the environment in which
          a command is run when the sudoers policy is in use.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 21 at 7:45

























          answered Feb 21 at 7:40









          Yaron

          8,54271838




          8,54271838











          • as I understand "file1" file need to have read permission, otherwise ti will give permission error: cp: cannot open ‘file1’ for reading: Permission denied
            – Hayk Hovhannisyan
            Feb 21 at 7:56











          • @HaykHovhannisyan - If I've solved your question, please accept my answer
            – Yaron
            Feb 21 at 8:01

















          • as I understand "file1" file need to have read permission, otherwise ti will give permission error: cp: cannot open ‘file1’ for reading: Permission denied
            – Hayk Hovhannisyan
            Feb 21 at 7:56











          • @HaykHovhannisyan - If I've solved your question, please accept my answer
            – Yaron
            Feb 21 at 8:01
















          as I understand "file1" file need to have read permission, otherwise ti will give permission error: cp: cannot open ‘file1’ for reading: Permission denied
          – Hayk Hovhannisyan
          Feb 21 at 7:56





          as I understand "file1" file need to have read permission, otherwise ti will give permission error: cp: cannot open ‘file1’ for reading: Permission denied
          – Hayk Hovhannisyan
          Feb 21 at 7:56













          @HaykHovhannisyan - If I've solved your question, please accept my answer
          – Yaron
          Feb 21 at 8:01





          @HaykHovhannisyan - If I've solved your question, please accept my answer
          – Yaron
          Feb 21 at 8:01


















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1008281%2fcopy-file-using-sudo-access%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          pylint3 and pip3 broken

          Missing snmpget and snmpwalk

          How to enroll fingerprints to Ubuntu 17.10 with VFS491