使用原生的系统terminal完成登录,
1、安装 pexpect 模块
$ pip install pexpect
2、案例
# -*- coding: utf-8 -*-
from paramiko import SSHClient, AutoAddPolicy
def ssh_init(self):
# 初始化ssh client
username = '***'
pwd = '***'
client = SSHClient()
client.set_missing_host_key_policy(AutoAddPolicy())
client.connect(hostname=self.host, port=22, username=username, password=pwd)
return client