Paramiko模块实现SSH密钥登陆
#!/usr/bin/python#-- coding:utf-8 --author = “Replaceroot”import paramikoprivate_key = paramiko.RSAKey.from_private_key_file(‘id_rsa102.txt’)ssh = paramiko.SSHClient()ssh.set_missing_host_key_policy(p
·
#!/usr/bin/python
#-- coding:utf-8 --
author = “Replaceroot”
import paramiko
private_key = paramiko.RSAKey.from_private_key_file(‘id_rsa102.txt’)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname = ‘192.168.0.104’, port=22, username=“root”, pkey=private_key)
stdin, stdout, stderr = ssh.exec_command(‘ifconfig’)
result = stdout.read()
print(result.decode())
ssh.close()
更多推荐
已为社区贡献1条内容
所有评论(0)