问题相关代码
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy)
private_key = paramiko.RSAKey.from_private_key_file('/root/.ssh/id_rsa')
ssh.connect(hostname='192.168.139.20', port=22, username='root', pkey=private_key)
stdin, stout, stderr = ssh.exec_command('head -5 /tmp/fstab')
cor_res = stout.read()
err_res = stderr.read()
print(cor_res.decode())
print(cor_res.decode())
ssh.close()
运行结果及报错内容
Traceback (most recent call last):
File "/python_project/module.py", line 74, in
ssh.connect(hostname='192.168.139.20', port=22, username='root', pkey=private_key)
File "/usr/local/lib/python3.6/site-packages/paramiko/client.py", line 362, in connect
server_key)
TypeError: missing_host_key() missing 1 required positional argument: 'key'