I have an AIX 6.1 server where I need to run a remote sudo command in a bash script.

Here is my bash script simplified:


set -x

sudo env

I can run the sudo command locally without password:

[user@server]$ sudo env

I can run the script locally:

[user@server]$ /tmp/testSudo.sh
+ sudo env

I can run sudo on the remote host:

[user@client]$ ssh user@server sudo env

I can run the script on the remote host with tty:

[user@client]$ ssh -t user@server /tmp/testSudo.sh
+ sudo env

I can't run the script on the remote host without tty (and I can't add the -t option in my context):

[user@client]$ ssh user@server /tmp/testSudo.sh
+ sudo env

It hangs there.

  • Does running sudo on the remote server require a password? – jw013 Jul 17 '13 at 17:12
  • So why not run ssh -t? – Gilles Jul 17 '13 at 23:47
  • @jw013 No there is no password required while runnig sudo on the remote server. – Pilou Jul 18 '13 at 7:56
  • @Gilles I'm making the request, is an extarnal program who does, so I can't change the ssh options. – Pilou Jul 18 '13 at 7:57
  • Possibly helpful: unix.stackexchange.com/q/79960/117549 – Jeff Schaller Jun 19 '18 at 20:15

Sudo when executed w/o terminal requires a helper program to handle password query:

SUDO_ASKPASS    Specifies the path to a helper program used to read the
password if no terminal is available or if the -A option is specified.

Normally when you connect via ssh and sudo will need a password but terminal is not allocated it will blow an error - on AIX this can behave different.

Check your sudo settings and enable NOPASSWD from all remote machines also, correct rule should look like that (add it on the end of /etc/sudoers) :

user ALL= NOPASSWD:/tmp/testSudo.sh

  • 2
    I don't understand why I need to add 'user ALL= NOPASSWD:/tmp/testSudo.sh' in my sudoers. This script is not played in a sudo but it plays a sudo : 'sudo env'. I allready have a line saying 'user ALL= NOPASSWD:env'. – Pilou Jul 18 '13 at 8:06
  • 8 mnths delay in answer - hope you accept that ;) I would make a try and use fullpath to env ( like '/usr/bin/env' ) both in sudo config and your script. – KWubbufetowicz Apr 5 '14 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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