我是靠谱客的博主 聪明牛排,最近开发中收集的这篇文章主要介绍Paramiko “Unknown Server“ 连接 ssh,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

cmd_to_execute = 'df -h'
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(server, username=username, password=password)
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(cmd_to_execute)
output = ssh_stdout.read().decode('utf-8')
print(output)
info_list = output.split('n')
size = used = available = percent = mount = ''
for index, info in enumerate(info_list):
if index == 8:
# print(index, info)
# print(info.split())
size, used, available, percent, mount = info.split()
print('size: ', size)
print('used: ', used)
print('available: ', available)
print('percent: ', percent)
print('mount: ', mount)
percent_int = int(percent[:-1])
if percent_int >= 80:
print('Disk usage is above 80%')
print(percent_int)
ssh.close()
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('127.0.0.1', username=username, password=password)
stdin, stdout, stderr = client.exec_command('ls -l')
import paramiko
from base64 import decodebytes
keydata = b"""AAAAB3NzaC1yc2EAAAABIwAAAQEA0hV..."""
key = paramiko.RSAKey(data=decodebytes(keydata))
client = paramiko.SSHClient()
client.get_host_keys().add('example.com', 'ssh-rsa', key)
client.connect(...)

参考
https://stackoverflow.com/questions/10670217/paramiko-unknown-server#43093883

https://stackoverflow.com/questions/53635843/paramiko-ssh-failing-with-server-not-found-in-known-hosts-when-run-on-we

最后

以上就是聪明牛排为你收集整理的Paramiko “Unknown Server“ 连接 ssh的全部内容,希望文章能够帮你解决Paramiko “Unknown Server“ 连接 ssh所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部