qianxunman

https://blog.csdn.net/qq_35958094/article/details/83348480?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase

模块安装:

pip install paramiko

import  paramiko
try:
    # 建立一个sshclient对象
    ssh = paramiko.SSHClient()
    # 允许将信任的主机自动加入到host_allow 列表,此方法必须放在connect方法的前面
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    # 调用connect方法连接服务器
    ssh.connect(hostname=\'****\', port=22, username=\'your name\', password=\'*****\')
    # 执行命令
    stdin, stdout, stderr = ssh.exec_command(\'ls -a\')
    print(\'进入hive\')
   
 
 
    # 结果放到stdout中,如果有错误将放到stderr中
    print(stdout.read().decode())
    # 关闭连接
    ssh.close()
except Exception as e:
    print(e)

分类:

技术点:

相关文章:

  • 2022-01-23
  • 2022-12-23
  • 2022-02-20
  • 2022-12-23
  • 2021-12-19
  • 2021-08-22
  • 2022-12-23
  • 2021-12-19
猜你喜欢
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2021-10-10
相关资源
相似解决方案