2

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:

testSudo.sh

#!/usr/bin/bash
set -x

sudo env

I can run the sudo command locally without password:

[user@server]$ sudo env
VAR=VAL
...

I can run the script locally:

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

I can run sudo on the remote host:

[user@client]$ ssh user@server sudo env
VAR=VAL
...

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

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

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.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Pilou
  • 83

1 Answers1

1

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

MAQ
  • 980
  • 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 08: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. – MAQ Apr 05 '14 at 14:42