代码改变世界

python3实现xshell登录远端服务器

2021-04-15 17:03  Tanwheey  阅读(369)  评论(0编辑  收藏  举报
使用原生的系统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