import subprocess
import os
(rfd, wfd) = os.pipe()
arg = "-d%d" % rfd
try:
p = subprocess.Popen(["sshpass",arg,"ssh","-l","haohzhang","phxaishdc9dn1447.stratus.phx.ebay.com","ls","/tmp/"], stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
os.close(rfd)
os.write(wfd,"PASSWORD\n")
os.close(wfd)
stdout, stderr = p.communicate()
print stdout, stderr
except OSError:
print("to use the 'ssh' connection type with passwords, you must install the sshpass program")
本文介绍了一种使用Python的subprocess模块结合sshpass程序实现SSH远程连接的方法,并演示了如何通过脚本自动输入密码进行认证的过程。
3788

被折叠的 条评论
为什么被折叠?



