无法使用 paramiko sudo su

unable to sudo su using paramiko

我正在使用 paramiko 连接到服务器,并且正在尝试切换到另一个用户。但我面临以下错误。

sudo: 不存在 tty 且未指定 askpass 程序

sudo: pam_authenticate: 对话错误

我已经尝试使用 "sudo -S" 选项,并在命令中传递密码。但没有运气。请帮我解决这个问题

我正在尝试从 windows 服务器连接到远程 linux 服务器,因此我无法使用 pexpect,因为它现在不支持 windows

PFB 脚本。

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



尝试将 sudo 合并到我需要通过 paramiko 执行的所有命令中,这似乎工作正常。运行良好的代码:

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