Execute a sudo NOPASSWD command remotely via SSH

Alex Spurling

I have a remote linux system that I can connect to via ssh and public key and then execute the following command:

sudo jetty restart

This command on this system is configured to allow anyone to execute without the sudo password. I.e. the sudoers file probably looks something like this

%develop ALL = NOPASSWD: /opt/scripts/jetty

This is great as we can execute this script with elevated privileges while keeping everything else locked down. The problem is when trying to execute this command remotely, I am always asked for the sudo password.

me@home:~$ ssh -t -i ~/.ssh/identity [email protected] 'sudo jetty restart'
Password: .....? (I don't have the sudo password!)

Is there a way I can execute this command remotely?

user1686

Make sure sudo is picking the right command; if there's a /usr/bin/jetty or such, the sudoers rule won't match. (Note that your ~/.bashrc and such files are ignored when using ssh <host> <command>, so your $PATH customizations never happen.)

sudo /opt/scripts/jetty restart should work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SSH: execute sudo command

From Dev

How to run a sudo command, remotely, trough SSH, using an IdentityFile?

From Dev

How to remote execute ssh command a sudo command without password

From Dev

Execute command on remote server via ssh

From Dev

R - Connect via ssh and execute a command

From Dev

Execute commands as different user via sudo over SSH in a justfile

From Dev

Execute commands as different user via sudo over SSH in a justfile

From Dev

ssh master - execute su remotely

From Dev

Use pty with ssh2 in node to execute command with sudo

From Dev

ssh to server and auto execute sudo command and keep the shell open

From Dev

gcloud compute execute command remotely

From Dev

Allow all commands via sudo but nopasswd for specific commands

From Dev

echo pwd remotely via ssh

From Dev

remotely executing a command using ssh

From Dev

Sudo execute command in Pythonscript

From Dev

Execute command with sudo and execute Bash script with sudo

From Dev

Script sudo via ssh

From Dev

Execute bash command with calling subshell $() via ssh with Here Document

From Dev

Execute command to remote server via SSH after exporting variable

From Dev

Sudo with NOPASSWD and service restart

From Dev

sudo NOPASSWD for particular paths

From Dev

NOPASSWD option not working in sudo

From Dev

Remotely execute programs via Amazon Alexa

From Dev

Streaming output of a remotely executed program via ssh

From Dev

How to check if a cdrom is in the tray remotely (via ssh)?

From Dev

Launching programs remotely via SSH on Windows 7

From Dev

Execute sudo command with Jsch Java

From Dev

Remotely run a command on a ssh-server with a script

From Dev

Remotely run a command on a ssh-server with a script

Related Related

HotTag

Archive