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
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for zdpapi_ssh-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f7fc14414d5ab5a996a39f0f27e20198e5cb6da9476fa69a84e188720864281 |
|
MD5 | 27731c2717a8e86daf5787f369b8c9ec |
|
BLAKE2b-256 | 5d7c6ba910da5f3e18429136da4ee7c66129695dafb9546fe2092758bdbdbf13 |