python 运维模块之 paramiko

用python链接服务器

1 基于用户名和密码的 sshclient 方式登录

import paramiko

ssh = paramiko.SSHClient()

Know_hosts = paramiko.AutoAddPolicy()

ssh.set_missing_host_key_policy(Know_hosts)


ssh.connect(
    hostname='47.104.102.87',
    port = 22,
    username="root",
    password= ""
)
# stdin,stdout,stderr = ssh.exec_command('ls')
stdin, stdout, stderr = ssh.exec_command('cd /kaikai && ls')
result = stdout.read().decode()
print result

ssh.close()


猜你喜欢

转载自blog.csdn.net/kaikai136412162/article/details/80857902