0

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)```



armzz_109
  • 45
  • 8
  • Hi Martin, I tried this already. But the "-S" option and "get_pty" option are just making my script hung there without showing any output or progress – armzz_109 Feb 20 '20 at 09:46
  • @Martin, The code is already pasted along with the question above. The thingg is, I am able to do the "sudo su test_user" from putty. Only via paramiko am having this issue – armzz_109 Feb 20 '20 at 10:40
  • Hi Martin, Thanks for support. The "sudo su" command is still not working. But I just tried incorporating sudo in all the commands that I need to execute via paramiko, and that seems to be working fine. code that worked fine: ``` stdin, stdout, stderr = ssh.exec_command('sudo -S chown -R test_user:test_user /tmp/test.txt') ``` – armzz_109 Feb 21 '20 at 08:24

1 Answers1

0

tried incorporating sudo in all the commands that I need to execute via paramiko, and that seems to be working fine. code that worked fine:

stdin, stdout, stderr = ssh.exec_command('sudo -S chown -R test_user:test_user /tmp/test.txt')

armzz_109
  • 45
  • 8