Python paramiko 怎么输入交互式的密码?

2018-12-20 17:55:37 +08:00
 DAPTX4869

要对华为的 IBMC 更改密码,官方文档只给了这么一个流程

https://s1.ax1x.com/2018/12/20/Fr1TgA.jpg

搜索了下交互输入就只有这个 s.exec_command('su -root') stdin.write('password') stdin.flush()

自己参考改了就是各种没反应... 或者报错

求教

4926 次点击
所在节点    Python
12 条回复
DAPTX4869
2018-12-20 17:58:43 +08:00
下班跑路顺手顶一下
xpresslink
2018-12-20 18:47:26 +08:00
调用 expect 来交互
littlewey
2018-12-20 18:53:26 +08:00
pyexpect

调 shell 用 sshpass
DAPTX4869
2018-12-20 19:05:42 +08:00
谢楼上各位,明天试试
leoleoasd
2018-12-20 19:12:53 +08:00
少个\n 吧...
DAPTX4869
2018-12-20 19:17:27 +08:00
@leoleoasd 你说的这可能性我也试了,凉凉
ThirdFlame
2018-12-20 19:31:33 +08:00
passwd 修改密码可以这样,你可以参照修改下试试
stdin, stdout, stderr = ssh_client.exec_command("passwd", timeout = 10)
stdin.write("{0}\n{1}\n{1}\n".format(old_password, new_password))
out,err = stdout.read(),stderr.read()
DAPTX4869
2018-12-20 20:11:10 +08:00
@ThirdFlame 好的,我明天测试
4linuxfun
2018-12-20 20:29:19 +08:00
可以试试 fabric,又 watcher,可以类似 pexpect 进行正则匹配后输入信息
DAPTX4869
2018-12-20 20:57:01 +08:00
@4linuxfun 现在还没涉及到你所说的功能...能输入就 ko 了
julyclyde
2018-12-21 13:43:26 +08:00
stdin 和 tty 不同的
ssh 是从 tty 读取密码的
DAPTX4869
2018-12-21 17:04:44 +08:00
@julyclyde 萌新不太清楚这个,学习了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/519479

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX