Restarting a service remotely with ssh and sudo errors

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











up vote
1
down vote

favorite












I am using the following command to try and restart a service



ssh username@server "systemctl restart storeapp.service"


However I am getting the following error message.



Failed to stop storeapp.service: Interactive authentication required.


I then tried



ssh -t username@server "systemctl restart storeapp.service"


This fails because it is not using the correct username to authenticate with it is skipping username@server for some other user. Authenticating as : otheruser. I so have ssh keys set. How can I over come this? Or is this a systems admin permissions issue?



If I run ssh username@server "systemctl status storeapp.service" that works and I can see the status of my service.










share|improve this question



























    up vote
    1
    down vote

    favorite












    I am using the following command to try and restart a service



    ssh username@server "systemctl restart storeapp.service"


    However I am getting the following error message.



    Failed to stop storeapp.service: Interactive authentication required.


    I then tried



    ssh -t username@server "systemctl restart storeapp.service"


    This fails because it is not using the correct username to authenticate with it is skipping username@server for some other user. Authenticating as : otheruser. I so have ssh keys set. How can I over come this? Or is this a systems admin permissions issue?



    If I run ssh username@server "systemctl status storeapp.service" that works and I can see the status of my service.










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am using the following command to try and restart a service



      ssh username@server "systemctl restart storeapp.service"


      However I am getting the following error message.



      Failed to stop storeapp.service: Interactive authentication required.


      I then tried



      ssh -t username@server "systemctl restart storeapp.service"


      This fails because it is not using the correct username to authenticate with it is skipping username@server for some other user. Authenticating as : otheruser. I so have ssh keys set. How can I over come this? Or is this a systems admin permissions issue?



      If I run ssh username@server "systemctl status storeapp.service" that works and I can see the status of my service.










      share|improve this question















      I am using the following command to try and restart a service



      ssh username@server "systemctl restart storeapp.service"


      However I am getting the following error message.



      Failed to stop storeapp.service: Interactive authentication required.


      I then tried



      ssh -t username@server "systemctl restart storeapp.service"


      This fails because it is not using the correct username to authenticate with it is skipping username@server for some other user. Authenticating as : otheruser. I so have ssh keys set. How can I over come this? Or is this a systems admin permissions issue?



      If I run ssh username@server "systemctl status storeapp.service" that works and I can see the status of my service.







      linux ubuntu systemd systemctl






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 31 at 15:35









      maulinglawns

      6,11621225




      6,11621225










      asked Aug 31 at 11:15









      user3525290

      1061




      1061




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Well, the easiest way to fix this would probably be to add:



          <username> ALL = NOPASSWD: /bin/systemctl restart storeapp.service


          To a file in /etc/sudoers.d, something like: /etc/sudoers.d/storeapp on the target server.



          This will allow you to run the command sudo systemctl restart storeapp.service without being prompted for a password.




          Working example using ufw
          On target host (Ubuntu 18.04):



          sudo cat /etc/sudoers.d/ufw 
          maulinglawns ALL = NOPASSWD: /bin/systemctl restart ufw


          On your server:



          ssh -t maulinglawns@<remote> 'sudo /bin/systemctl restart ufw'
          maulinglawns@<remote>'s password:
          Connection to <remote> closed.
          echo $?
          0


          As you can see from above, I am prompted once (since I don't use a key), but not for the sudo command. And the exit status tells us that we succeeded in restarting ufw without password. Which I can also verify by checking /var/log/syslog.




          Obviously, this will only work if you have a) root access to the target server, otherwise b) ask the hopefully friendly sysadmin if this is doable and/or acceptable. If a) always use visudo when editing/creating sudoer files!




          If I run ssh username@server "systemctl status storeapp.service" that
          works and I can see the status of my service.




          Yes, status does not always require elevated rights.






          share|improve this answer






















          • Thanks will give this a shot. Guessing the answer is probably a no.
            – user3525290
            Aug 31 at 12:16










          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: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2funix.stackexchange.com%2fquestions%2f466006%2frestarting-a-service-remotely-with-ssh-and-sudo-errors%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
          0
          down vote













          Well, the easiest way to fix this would probably be to add:



          <username> ALL = NOPASSWD: /bin/systemctl restart storeapp.service


          To a file in /etc/sudoers.d, something like: /etc/sudoers.d/storeapp on the target server.



          This will allow you to run the command sudo systemctl restart storeapp.service without being prompted for a password.




          Working example using ufw
          On target host (Ubuntu 18.04):



          sudo cat /etc/sudoers.d/ufw 
          maulinglawns ALL = NOPASSWD: /bin/systemctl restart ufw


          On your server:



          ssh -t maulinglawns@<remote> 'sudo /bin/systemctl restart ufw'
          maulinglawns@<remote>'s password:
          Connection to <remote> closed.
          echo $?
          0


          As you can see from above, I am prompted once (since I don't use a key), but not for the sudo command. And the exit status tells us that we succeeded in restarting ufw without password. Which I can also verify by checking /var/log/syslog.




          Obviously, this will only work if you have a) root access to the target server, otherwise b) ask the hopefully friendly sysadmin if this is doable and/or acceptable. If a) always use visudo when editing/creating sudoer files!




          If I run ssh username@server "systemctl status storeapp.service" that
          works and I can see the status of my service.




          Yes, status does not always require elevated rights.






          share|improve this answer






















          • Thanks will give this a shot. Guessing the answer is probably a no.
            – user3525290
            Aug 31 at 12:16














          up vote
          0
          down vote













          Well, the easiest way to fix this would probably be to add:



          <username> ALL = NOPASSWD: /bin/systemctl restart storeapp.service


          To a file in /etc/sudoers.d, something like: /etc/sudoers.d/storeapp on the target server.



          This will allow you to run the command sudo systemctl restart storeapp.service without being prompted for a password.




          Working example using ufw
          On target host (Ubuntu 18.04):



          sudo cat /etc/sudoers.d/ufw 
          maulinglawns ALL = NOPASSWD: /bin/systemctl restart ufw


          On your server:



          ssh -t maulinglawns@<remote> 'sudo /bin/systemctl restart ufw'
          maulinglawns@<remote>'s password:
          Connection to <remote> closed.
          echo $?
          0


          As you can see from above, I am prompted once (since I don't use a key), but not for the sudo command. And the exit status tells us that we succeeded in restarting ufw without password. Which I can also verify by checking /var/log/syslog.




          Obviously, this will only work if you have a) root access to the target server, otherwise b) ask the hopefully friendly sysadmin if this is doable and/or acceptable. If a) always use visudo when editing/creating sudoer files!




          If I run ssh username@server "systemctl status storeapp.service" that
          works and I can see the status of my service.




          Yes, status does not always require elevated rights.






          share|improve this answer






















          • Thanks will give this a shot. Guessing the answer is probably a no.
            – user3525290
            Aug 31 at 12:16












          up vote
          0
          down vote










          up vote
          0
          down vote









          Well, the easiest way to fix this would probably be to add:



          <username> ALL = NOPASSWD: /bin/systemctl restart storeapp.service


          To a file in /etc/sudoers.d, something like: /etc/sudoers.d/storeapp on the target server.



          This will allow you to run the command sudo systemctl restart storeapp.service without being prompted for a password.




          Working example using ufw
          On target host (Ubuntu 18.04):



          sudo cat /etc/sudoers.d/ufw 
          maulinglawns ALL = NOPASSWD: /bin/systemctl restart ufw


          On your server:



          ssh -t maulinglawns@<remote> 'sudo /bin/systemctl restart ufw'
          maulinglawns@<remote>'s password:
          Connection to <remote> closed.
          echo $?
          0


          As you can see from above, I am prompted once (since I don't use a key), but not for the sudo command. And the exit status tells us that we succeeded in restarting ufw without password. Which I can also verify by checking /var/log/syslog.




          Obviously, this will only work if you have a) root access to the target server, otherwise b) ask the hopefully friendly sysadmin if this is doable and/or acceptable. If a) always use visudo when editing/creating sudoer files!




          If I run ssh username@server "systemctl status storeapp.service" that
          works and I can see the status of my service.




          Yes, status does not always require elevated rights.






          share|improve this answer














          Well, the easiest way to fix this would probably be to add:



          <username> ALL = NOPASSWD: /bin/systemctl restart storeapp.service


          To a file in /etc/sudoers.d, something like: /etc/sudoers.d/storeapp on the target server.



          This will allow you to run the command sudo systemctl restart storeapp.service without being prompted for a password.




          Working example using ufw
          On target host (Ubuntu 18.04):



          sudo cat /etc/sudoers.d/ufw 
          maulinglawns ALL = NOPASSWD: /bin/systemctl restart ufw


          On your server:



          ssh -t maulinglawns@<remote> 'sudo /bin/systemctl restart ufw'
          maulinglawns@<remote>'s password:
          Connection to <remote> closed.
          echo $?
          0


          As you can see from above, I am prompted once (since I don't use a key), but not for the sudo command. And the exit status tells us that we succeeded in restarting ufw without password. Which I can also verify by checking /var/log/syslog.




          Obviously, this will only work if you have a) root access to the target server, otherwise b) ask the hopefully friendly sysadmin if this is doable and/or acceptable. If a) always use visudo when editing/creating sudoer files!




          If I run ssh username@server "systemctl status storeapp.service" that
          works and I can see the status of my service.




          Yes, status does not always require elevated rights.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 31 at 15:37

























          answered Aug 31 at 11:52









          maulinglawns

          6,11621225




          6,11621225











          • Thanks will give this a shot. Guessing the answer is probably a no.
            – user3525290
            Aug 31 at 12:16
















          • Thanks will give this a shot. Guessing the answer is probably a no.
            – user3525290
            Aug 31 at 12:16















          Thanks will give this a shot. Guessing the answer is probably a no.
          – user3525290
          Aug 31 at 12:16




          Thanks will give this a shot. Guessing the answer is probably a no.
          – user3525290
          Aug 31 at 12:16

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f466006%2frestarting-a-service-remotely-with-ssh-and-sudo-errors%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?