Python登录SSH服务遇到报错,paramiko.ssh_exception.SSHException: Channel closed.
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python登录SSH服务遇到报错,paramiko.ssh_exception.SSHException: Channel closed.相关的知识,希望对你有一定的参考价值。
ssh登录的时候链接端口失败这由于server端没有开机或是网络不通(这个原因很多,最简单的是网线没有插。还有就是可能会是网卡down了等)如果是网卡down了ifup相应的网卡再试试 参考技术A
我也遇到同样的问题,我用putty可以ssh正常登陆到H3C交换机,说明肯定不是网络不通,或者参数设置的问题。同样用python的paramiko模块登陆Linux正常,就是登陆H3C交换机出现该问题。现将完整出错信息附上,求各位大神帮忙!
程序代码
================
# -*- coding: utf-8 -*-
import paramiko
import ssh
# 创建SSH对象
ssh = paramiko.SSHClient()
# 允许连接不在known_hosts文件上的主机
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# 连接服务器
ssh.connect(hostname="141.52.44.128", port=22, username="dsj-ssh", password="dsj-ssh")
stdin, stdout, stderr = ssh.exec_command('dis cpu')#执行到该语句的时候出错
result = stdout.read().decode()
err = stderr.read()
# 关闭连接
ssh.close()
print(stdin, result, err)
================
出错信息
Traceback (most recent call last):
Python Shell, prompt 23, line 1
File "C:\\Python35\\Lib\\site-packages\\paramiko\\client.py", line 486, in exec_command
chan.exec_command(command)
File "C:\\Python35\\Lib\\site-packages\\paramiko\\channel.py", line 63, in _check
return func(self, *args, **kwds)
File "C:\\Python35\\Lib\\site-packages\\paramiko\\channel.py", line 241, in exec_command
self._wait_for_event()
File "C:\\Python35\\Lib\\site-packages\\paramiko\\channel.py", line 1198, in _wait_for_event
raise e
paramiko.ssh_exception.SSHException: Channel closed.
Python3.6.2安装pip install paramike模块报错
问题描述: 在有几台电脑上pip install paramike报错
报错内容:
Could not fetch URL https://pypi.python.org/simple/pip/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590) - skipping
Requirement already up-to-date: pip in /usr/local/lib/python2.7/dist-packages/pip-9.0.1-py2.7.egg
ReadTimeoutError: HTTPSConnectionPool(host=‘pypi.python.org‘, port=443):Read timed out
解决方法:
使用豆瓣源安装
pip install -i https://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com paramike
以上是关于Python登录SSH服务遇到报错,paramiko.ssh_exception.SSHException: Channel closed.的主要内容,如果未能解决你的问题,请参考以下文章
Python3.6.2安装pip install paramike模块报错
Python实现ssh登录远程Ubuntu,并实现命令行的收发
python ssh登录网管后继续ssh登录其它机器,咋写接下来的代码?
gitlab-登录账户遇到ERROR: Permission to XXX.git denied to user报错怎么办