[英]Python paramiko sending sudo password and other data to command
我想使用ssh和Python更改Ubuntu用户密码。
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('xxx.xxx.xxx.xxx', username='xxx', password='xxx')
stdin,stdout,stderr = client.exec_command('sudo passwd test1')
stdin.write('passForSudo' + '\n')
stdin.write('newPassForUser' + '\n')
stdin.write('newPassForUser' + '\n')
stdin.flush()
为什么这不起作用? 我找不到解决办法(
默认情况下,sudo不从stdin读取密码,而是从终端读取密码。
须藤给:
...
-S, --stdin
Write the prompt to the standard error and read the password from the standard
input instead of using the terminal device. The password must be followed by a
newline character.
您应该在sudo中使用此选项。
最好的祝福
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.