使用paramiko模块远程连接遇到paramiko.ssh_exception.NoValidConnectionsError的解决办法
2018-01-22 13:11
876 查看
初学paramiko模块,想尝试在windows上远程登录ubuntu.
首先写了以下代码:
#创建用于连接远程服务器的客户端并执行基本命令
import paramiko
# 创建SSH对象
ssh = paramiko.SSHClient()
# 允许连接不在know_hosts文件中的主机
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# 连接服务器
ssh.connect(hostname="192.168.1.103",port=22,username="root1",password="123456")
# 执行命令
stdin,stdout,stderr = ssh.exec_command("df")
result = stdout.read()
# 打印输出
print(result.decode())
# 关闭连接
ssh.close()
然后打开虚拟机开了一个ubuntu,执行时,却遇到了提示:paramiko.ssh_exception.NoValidConnectionsError的错误。
这个说明了连接不到服务器,我也仔细检查了ip,用户名,密码都没问题。最后把问题锁定在22端口上面。
解决办法:
首先在ubuntu终端上输入:cat / etc/ssh/ssh_config,检查发现ssh端口号为22端口没错。
然后执行命令:netstat -ntl,查看22端口是否开通
发现果然没有开通22端口,于是下面就开通 22端口就可以解决问题了。
1.关闭防火墙,命令:sudo ufw disable
2.安装openSSH,命令:sudo apt install openssh-server openssh-client
3.查看22端口是否打开:netstat -ntl
然后就成功地开通了22端口。
最后执行代码:命令成功的返回了。
首先写了以下代码:
#创建用于连接远程服务器的客户端并执行基本命令
import paramiko
# 创建SSH对象
ssh = paramiko.SSHClient()
# 允许连接不在know_hosts文件中的主机
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# 连接服务器
ssh.connect(hostname="192.168.1.103",port=22,username="root1",password="123456")
# 执行命令
stdin,stdout,stderr = ssh.exec_command("df")
result = stdout.read()
# 打印输出
print(result.decode())
# 关闭连接
ssh.close()
然后打开虚拟机开了一个ubuntu,执行时,却遇到了提示:paramiko.ssh_exception.NoValidConnectionsError的错误。
这个说明了连接不到服务器,我也仔细检查了ip,用户名,密码都没问题。最后把问题锁定在22端口上面。
解决办法:
首先在ubuntu终端上输入:cat / etc/ssh/ssh_config,检查发现ssh端口号为22端口没错。
然后执行命令:netstat -ntl,查看22端口是否开通
发现果然没有开通22端口,于是下面就开通 22端口就可以解决问题了。
1.关闭防火墙,命令:sudo ufw disable
2.安装openSSH,命令:sudo apt install openssh-server openssh-client
3.查看22端口是否打开:netstat -ntl
然后就成功地开通了22端口。
最后执行代码:命令成功的返回了。
相关文章推荐
- 使用ProGuard遇到“conversion to Dalvik format failed with error 1”错误的解决办法
- [Android]使用ProGuard遇到“conversion to Dalvik format failed with error 1”错误的解决办法
- [Android]使用ProGuard遇到“conversion to Dalvik format failed with error 1”错误的解决办法
- mysql远程连接:ERROR 1130 (HY000): Host '*.*.*.*' is not allowed to connect to this MySQL server解决办法
- Error:System.Data.SqlClient.SqlException: 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误,请检查远程连接是否开启。解决方法
- linux中远程连接(如SSH)出现someone could be eavesdropping on you right now的解决办法
- 收集的linux远程ssh连接putty失败解决办法!
- ubuntu下ssh连接远程主机特别慢的解决办法
- (转)远程连接webservice遇到无法访问的问题解决办法
- mysql不支持远程连接的解决办法(#报错:1130-host ... is not allowed to connect to this MySql server 开放mysql远程连接 不使用lo
- Linux下SSH远程连接断开后让程序继续运行解决办法
- 使用Microsoft Update升级时遇到 Server Error 403 - Forbidden:Access is denied错误的解决办法
- mysql远程连接:ERROR 1130 (HY000): Host '*.*.*.*' is not allowed to connect to this MySQL server解决办法
- 远程连接webservice遇到无法访问的问题解决办法
- 使用jdbcTemplate.queryForRowSet()遇到UncategorizedSQLException:Invalid precision value. Cannot be less than zero解决办法
- [Android]使用ProGuard遇到“conversion to Dalvik format failed with error 1”错误的解决办法
- 远程SSH连接Putty失败解决办法
- 如何解决sql server2005的“不允许远程连接”错误.(how to resolve the error: "SQL Server does not allow remote connections" for SQL Server2005)
- 使用远程桌面功能登录系统,常常遇到类似“由于帐户限制,你无法登录”的提示的解决办法
- mysql远程连接:ERROR 1130 (HY000): Host '*.*.*.*' is not allowed to connect to this MySQL server解决办法