import paramiko
import time
# 服务器相关信息,下面输入你个人的用户名、密码、ip、linux命令等信息
ip = "172.16.1.7"
port = 22
user = "root"
password = "112233"
# 输入linux命令
commands = ["pwd", "ll"]
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# 建立连接
ssh.connect(ip, port, user, password, timeout=10)
channel = ssh.invoke_shell(width=800)
for command in commands:
channel.send(command + "\n") # 发送指令
while not channel.recv_ready(): # 等待数据到达
time.sleep(1)
output = channel.recv(40960)
print(output.decode())
ssh.close()
Python3 连接服务器操作linux命令,使用paramiko库
最新推荐文章于 2023-03-07 20:12:59 发布