0
我使用Python子进程运行在远程服务器上的命令:子流程示出了输入密码
p=subprocess.Popen('ssh [email protected] "sudo do_something"', shell=True)
当我键入密码,它出现在屏幕上 - 而不是从外壳运行此,密码是隐藏的。
有没有办法可以禁用这个输入回声?
我使用Python子进程运行在远程服务器上的命令:子流程示出了输入密码
p=subprocess.Popen('ssh [email protected] "sudo do_something"', shell=True)
当我键入密码,它出现在屏幕上 - 而不是从外壳运行此,密码是隐藏的。
有没有办法可以禁用这个输入回声?
如果你必须输入一些应该自动化的东西,你可能需要考虑使用pexpect:http://www.noah.org/wiki/Pexpect 这样你可以事先询问你的用户密码(使用getpass模块),然后让你的脚本“type “虚拟密码。
在上面提到的网站上有几个写得很好的例子,描述了如何去做你所需要的。
删除'shell = True' – 2012-03-19 09:55:26
你可能想咨询到这个线程http://stackoverflow.com/questions/1787288/how-to-call-ssh-by-subprocess-module-so-that-it- uses-ssh-askpass-variable – bpgergo 2012-03-19 09:55:34
['fabric'](http://fabfile.org)可能对在远程服务器上运行命令很有用。 – jfs 2012-03-19 10:20:56