I use Paramiko to connect with my unix host with goal to execute the the following commands:
whoami--> This will print PAM functional accounthostname--> hostname of the unix serversudo su– (for sudo no password is required, it automatically takes to root user) --> This will take it to root userwhoami--> this should print root
The #1 and #2 commands works fine and in the stdout response can see the expected result.
trans.auth_interactive(username='username', handler=handler)
session = trans.open_session()
stdout_data = None
stderr_data = None
(stdin, stdout, stderr) = session.exec_command("sudo su -")
command = 'whoami'
stdin.write(command + '\n')
stdin.flush()
result = stdout.readlines()
print(result)
output = str(result)
print(output)
print_hi('done')
Console logs
INFO:paramiko.transport:Authentication (keyboard-interactive) successful!
DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes
DEBUG:paramiko.transport:[chan 0] Max packet out: 32768 bytes
DEBUG:paramiko.transport:Secsh channel 0 opened.
DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok
Traceback (most recent call last):
File "C:/Users/tpukrisi/PycharmProjects/Paramiko/paramikoppam.py", line 77, in <module>
connect_pam_host()
File "C:/Users/tpukrisi/PycharmProjects/Paramiko/paramikoppam.py", line 21, in connect_pam_host
(stdin, stdout, stderr) = session.exec_command("sudo su -")
TypeError: cannot unpack non-iterable NoneType object
DEBUG:paramiko.transport:EOF in transport thread
Process finished with exit code 1
Thanks Krishna