#### ip,运行的脚步也可是命令
def linux(ip,mmm):
# 创建SSH对象
ssh = paramiko.SSHClient()
# 允许连接不在know_hosts文件中的主机
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# 连接服务器
ssh.connect(ip, port=port, username=username, password=password )
stdin, stdout, stderr = ssh.exec_command(mmm)
# stdin, stdout, stderr = ssh.exec_command("df")
# 获取命令结果
res, err = stdout.read(), stderr.read()
result = res if res else err
print(result.decode())
# 关闭连接
ssh.close()
#登录的用户名
username = 'root'
#登录的密码
password = '******'
#端口
port = **
#ip
ip = '*.*.*.*'
linux("%s"%ip,"sh /**/***.sh")
python Windows登录远程的Linux系统执行命令
最新推荐文章于 2024-05-05 18:39:57 发布