简体   繁体   English

无法使用 paramiko sudo su

[英]unable to sudo su using paramiko

I am connected to a server using paramiko and am trying to switch to another user.我使用 paramiko 连接到服务器,并试图切换到另一个用户。 But I am facing the below errors.但我面临以下错误。

sudo: no tty present and no askpass program specified sudo:不存在 tty 且未指定 askpass 程序

sudo: pam_authenticate: Conversation error须藤:pam_authenticate:对话错误

I have tried option with "sudo -S" and also passing password along with command.我已经尝试使用“sudo -S”选项,并且还通过命令传递密码。 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我正在尝试从 Windows 服务器连接到远程 linux 服务器,因此我无法使用 pexpect,因为它现在一天不支持 Windows

PFB the script. 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)```



tried incorporating sudo in all the commands that I need to execute via paramiko, and that seems to be working fine.尝试将 sudo 合并到我需要通过 paramiko 执行的所有命令中,这似乎工作正常。 code that worked fine:运行良好的代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM