Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|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

1 Answer 1

up vote 2 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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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