Paramiko and Pseudo-tty Allocation

Jon picture Jon · May 26, 2010 · Viewed 21.5k times · Source

I'm trying to use Paramiko to connect to a remote host and execute a number of text file substitutions.

i, o, e = client.exec_command("perl -p -i -e 's/" + initial + "/" 
                              + replaced + "/g'" + conf);

Some of these commands need to be run as sudo, which results in:

sudo: sorry, you must have a tty to run sudo

I can force pseudo-tty allocation with the -t switch and ssh.

Is it possible to do the same thing using paramiko?

Answer

Maciej Wawrzyńczuk picture Maciej Wawrzyńczuk · Feb 3, 2015

Actually it's quite simple. Just:

stdin, stdout, stderr = client.exec_command(command,  get_pty=True)