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 me@remote.server.com 'sudo jetty restart'
Password: .....? (I don't have the sudo password!)

Is there a way I can execute this command remotely?

link|improve this question
"ssh -t -i ~/.ssh/identity me@remote.server.com" lets you login without a password prompt, I presume? Just making sure that the password prompt you are seeing is not just an ssh login and not sudo. – Janne Pikkarainen Sep 10 '10 at 9:42
requiretty is off? There is also a tty_tickets parameter you wish to examine. – MattBianco Sep 10 '10 at 10:05
Yes, when I don't specify the command to execute, ssh logs in with no problem. I'm not sure whether requiretty is on or off but grawity's answer below does the trick. – Alex Spurling Sep 13 '10 at 8:59
When using ssh -t a tty is always allocated. Besides, with requiretty, sudo would fail before asking for a password. – grawity Sep 13 '10 at 13:12
feedback

1 Answer

up vote 1 down vote accepted

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.

link|improve this answer
Thanks! that works! – Alex Spurling Sep 13 '10 at 8:54
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.