I saw other useful discussion but not found
import paramiko
ssh = paramiko.SSHClient ()
ssh.set_missing_host_key_policy (paramiko.AutoAddPolicy ())
ssh.connect ( '192.168.0.13', username = 'aa', password = 'aa')
stdin, stdout, stderr = ssh.exec_command ( "sudo reboot")
stdin.write ( 'aa \ n')
stdin.flush ()
data = stdout.read () + stderr.read ()
print (data)
ssh.close ()
This code should perform like ‘sudo reboot’ and accordingly send the password ‘aa’ that would sudo to run, but it does not, why? The code itself is executed without errors
UPD: I checked, and it is connected “is”
Answer 1
This is probably because a password is required to enter the terminal, and you have not provided any terminal. Try ssh.exec_command (…, get_pty = True) andreymal
Answer 2
Try the following code:
import paramiko
client = paramiko.SSHClient ()
client.set_missing_host_key_policy (paramiko.AutoAddPolicy ())
client.connect (...)
slient.get_transport channel = (). open_session ()
channel.get_pty ()
channel.settimeout (5)
channel.exec_command ( 'sudo reboot')
channel.send (password + '\ n')
print channel.recv (1024)
channel.close ()
client.close ()