using python Paramiko for ssh: sudo: no tty present and no askpass program specified

Posted by misteryes on Super User See other posts from Super User or by misteryes
Published on 2013-04-09T23:32:42Z Indexed on 2014/05/29 15:32 UTC
Read the original article Hit count: 444

Filed under:
|
|

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!

© Super User or respective owner

Related posts about linux

Related posts about ssh