当前位置:   article > 正文

paramiko私钥连接(centos7)_paramiko ssh centos7

paramiko ssh centos7
更改ssh配置vim /etc/ssh/sshd_config或vim /etc/ssh/ssh_config
  1. StrictModes no  
  2. RSAAuthentication yes
  3. PubkeyAuthentication yes
  4. AuthorizedKeysFile      .ssh/authorized_keys      #ssh文件位置
  5. PasswordAuthentication yes                        #使用密码  no为不使用密码
  1. 重启ssh服务
systemctl restart sshd.service
  1. 测试代码
  1. # -*- coding:utf-8 -*-
  2. import paramiko
  3. import sys
  4. import os
  5. default_key_file = os.path.join(sys.path[0], 'download', 'id_rsa')
  6. # default_key_file = 'D:/Study/Python/test/Paramiko/download/id_rsa'
  7. private_key = paramiko.RSAKey.from_private_key_file(default_key_file, password='123456')
  8. ssh_client = paramiko.SSHClient()
  9. ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
  10. ssh_client.connect(hostname='192.168.86.128', port=22, username='root', pkey=private_key)
  11. stdin, stdout, stderr = ssh_client.exec_command('ls -l')
  12. print stdout.readline()
  13. ssh_client.close()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/603464
推荐阅读
相关标签
  

闽ICP备14008679号