Restarting a service remotely with ssh and sudo errors
Clash 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.
linux ubuntu systemd systemctl
add a comment |Â
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.
linux ubuntu systemd systemctl
add a comment |Â
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.
linux ubuntu systemd systemctl
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
linux ubuntu systemd systemctl
edited Aug 31 at 15:35
maulinglawns
6,11621225
6,11621225
asked Aug 31 at 11:15
user3525290
1061
1061
add a comment |Â
add a comment |Â
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.
Thanks will give this a shot. Guessing the answer is probably a no.
â user3525290
Aug 31 at 12:16
add a comment |Â
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.
Thanks will give this a shot. Guessing the answer is probably a no.
â user3525290
Aug 31 at 12:16
add a comment |Â
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.
Thanks will give this a shot. Guessing the answer is probably a no.
â user3525290
Aug 31 at 12:16
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password