paramiko模块基于ssh,用于连接远程服务器并执行相关操作。

sshclient:用于连接远程服务器并执行基本命令:

import paramiko

# 创建ssh对象
ssh = paramiko.SSHClient()
# 允许连接不在know_hosts文件中的主机
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# 连接服务器
ssh.connect(hostname='192.168.254.130', port=22, username='root',
            password='123456')
# 执行命令
stdin, stdout, stderr = ssh.exec_command('service iptables stop')
# 获取命令执行结果
result = stdout.read()
print(result.decode())
# 关闭连接
ssh.close()
基于用户名和密码连接

相关文章:

  • 2021-07-24
  • 2022-02-05
  • 2021-11-01
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-18
  • 2021-07-17
  • 2018-04-10
  • 2021-11-08
  • 2021-08-18
相关资源
相似解决方案