带有 paramiko 的 ssh 客户端 (python)
# sshpy v1 by s0urd
# simple ssh client
# irc.gonullyourself.org 6667 #code
import paramiko
import os
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
privatekey = os.path.expanduser('/home/rabia/private')
mkey = paramiko.RSAKey.from_private_key_file(privatekey)
ssh.connect('78.46.172.47', port=22, username='s0urd', password=None, pkey=mkey)
while True:
pick = raw_input("sshpy: ")
stdin, stdout, stderr = ssh.exec_command(pick)
print stdout.readlines()
ssh.close()
当我尝试运行超过 1 个命令时,出现此错误:
AttributeError: 'NoneType' object has no attribute 'open_session'
# sshpy v1 by s0urd
# simple ssh client
# irc.gonullyourself.org 6667 #code
import paramiko
import os
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
privatekey = os.path.expanduser('/home/rabia/private')
mkey = paramiko.RSAKey.from_private_key_file(privatekey)
ssh.connect('78.46.172.47', port=22, username='s0urd', password=None, pkey=mkey)
while True:
pick = raw_input("sshpy: ")
stdin, stdout, stderr = ssh.exec_command(pick)
print stdout.readlines()
ssh.close()
When I try to run more then 1 command I get this error:
AttributeError: 'NoneType' object has no attribute 'open_session'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来是因为在
while
循环结束时执行了ssh.close()
(从而关闭会话)。Looks like it's because at the end of the
while
loop you dossh.close()
(thus closing the session).