5
1
I want to use paramiko
to ssh into a bunch a remote nodes and run some command line with root
priviledge
I have ssh key in my home directory and so i don't need to input password when I ssh into those remote nodes
but when running the following script:
def connect(hostname):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname, username='niky', pkey=paramiko.RSAKey.from_private_key(open('id_rsa'), 'passwd'), timeout = 240.0) return ssh
def run(hostname):
ssh = connect(hostname)
(stdin, stdout, stderr) = ssh.exec_command("sudo ls")
res = stderr.readlines()
print hostname+': '+''.join(str(elem) for elem in res)+'\n'
run(remote.nity.com)
I got the following error:
remote.nity.com: sudo: no tty present and no askpass program specified
if I don't add sudo
before ls
everything works fine
what are potential reasons ?
thanks!
the user who runs the sudo must not have been allowed to run the command(s) you are running, with NOPASSWORD directive in sudoers file – MelBurslan – 2013-04-10T04:34:30.213