Skip to main content

python实现ssh操作

Project description

zdpapi_shh

python实现ssh操作,基于paramiko二次封装

安装方式:

pip install zdpapi_ssh

一、快速入门

1.1 建立连接

paramiko方式

import paramiko

# 建立一个sshclient对象
ssh = paramiko.SSHClient()

# 允许将信任的主机自动加入到host_allow 列表,此方法必须放在connect方法的前面
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# 调用connect方法连接服务器
ssh.connect(hostname='192.168.18.11', port=22,
            username='zhangdapeng', password='zhangdapeng')

# 执行命令
stdin, stdout, stderr = ssh.exec_command('df -hl')

# 结果放到stdout中,如果有错误将放到stderr中
print(stdout.read().decode())

# 关闭连接
ssh.close()

zdpapi_shh方式



          

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zdpapi_ssh-0.1.0.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

zdpapi_ssh-0.1.0-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page