python连接 ssh

 

import paramiko

# private = paramiko.RSAKey.from_private_key()   秘钥

trans = paramiko.Transport(("123.*.*。*",22))
trans.connect(username='root',password='***************')

# 通信
ssh = paramiko.SSHClient()
ssh._transport = trans

# 执行shell命令
stdin, stdout, stderror = ssh.exec_command("ls -la")
print(stdout.read().decode('utf-8'))

 

posted @ 2019-12-28 14:16  流年中渲染了微笑  阅读(157)  评论(0编辑  收藏  举报