天河超算,使用Python自动ssh

1)先上代码

复制代码
import paramiko
 
transport = paramiko.Transport(("ip地址", 22))
transport.connect(username="username", password="passwd")              # 建立连接
 
# 创建SSH对象
ssh = paramiko.SSHClient()
ssh._transport = transport
 
# 执行命令,不要执行top之类的在不停的刷新的命令
stdin, stdout, stderr = ssh.exec_command("ls ")
 
# 获取命令结果
res, err = stdout.read(), stderr.read()
result = res if res else err
print(result.decode())
 
# 关闭服务器连接
transport.close()

2)执行

python test_ssh.py

3)运行结果

相关推荐
老师好,我是刘同学21 分钟前
Python执行命令并保存输出到文件
python
啵啵鱼爱吃小猫咪2 小时前
机械臂阻抗控制github项目-mujoco仿真
开发语言·人工智能·python·机器人
似水明俊德2 小时前
02-C#
开发语言·c#
MaximusCoder2 小时前
等保测评命令——Centos Linux
linux·运维·经验分享·python·安全·centos
yunyun321232 小时前
用Python生成艺术:分形与算法绘图
jvm·数据库·python
m0_662577972 小时前
高级爬虫技巧:处理JavaScript渲染(Selenium)
jvm·数据库·python
oem1102 小时前
C++中的享元模式实战
开发语言·c++·算法
songyuc3 小时前
【PyTorch】感觉`CrossEntropyLoss`和`BCELoss`很类似,为什么它们接收labels的shape常常不一样呢?
人工智能·pytorch·python
似水明俊德3 小时前
01-C#.Net-泛型-面试题
java·开发语言·面试·c#·.net
ℳ๓₯㎕.空城旧梦3 小时前
Python单元测试(unittest)实战指南
jvm·数据库·python