I am connected to a server using paramiko and am trying to switch to another user. But I am facing the below errors.
sudo: no tty present and no askpass program specified
sudo: pam_authenticate: Conversation error
I have tried option with "sudo -S" and also passing password along with command. But no luck. Please help me to solve this
I am trying to connect to a remote linux server from windows server and so I am not able to use pexpect as it does not support windows now a days
PFB the script.
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, username=user, password=pwd)
print("Connected to: ", host)
stdin, stdout, stderr = ssh.exec_command('sudo su test_user')
if stdin:
print("asked for inp: ", stdin)
stdin.write(pwd+"\n")
stdin.flush()
error = ""
output = ""
for err in stderr.readlines():
error = error + err
if error != "":
print("error: ", error)```