模块的使用:paramiko、django-session-security、shellinabox

本节内容:

1:paramiko 模块

2:django-session-security模块

3:shellinabox模块

 

1:paramiko 模块

paramiko  用户创建ssh的客户端     https://github.com/paramiko/paramiko

使用方式:

#!/usr/bin/env python
#coding:utf-8

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.1.108', 22, 'alex', '123')
stdin, stdout, stderr = ssh.exec_command('df')
print stdout.read()
ssh.close();
执行命令-通过用户名密码
import paramiko

private_key_path = '/home/auto/.ssh/id_rsa'
key = paramiko.RSAKey.from_private_key_file(private_key_path)

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('主机名 ', 端口, '用户名', key)

stdin, stdout, stderr = ssh.exec_command('df')
print stdout.read()
ssh.close()
执行命令-通过密钥链接
import paramiko

t = paramiko.Transport(('47.100.111.141', 22))
t.connect(username='web', password='redhat')   ###创建了一个对象,将t这个对象再给from_transport
sftp = paramiko.SFTPClient.from_transport(t)
sftp.put("d:\\requirements.txt","/tmp/qwer.tex",)  ##本地文件==》远程文件
t.close()
上传文件-通过用户名密码
import paramiko

pravie_key_path = '/home/auto/.ssh/id_rsa'
key = paramiko.RSAKey.from_private_key_file(pravie_key_path)

t = paramiko.Transport(('182.92.219.86',22))
t.connect(username='wupeiqi',pkey=key)

sftp = paramiko.SFTPClient.from_transport(t)
sftp.get('/tmp/test3.py','/tmp/test4.py')   ## 远程文件==》本地文件 

t.close()
下载文件-通过密钥

2:django-session-security模块

django-session-security		启动js的计时三十分钟 没点击,页面失效重新登陆    pip install django-session-security

3:shellinabox模块

shellinabox 用于页面的ssh: https://github.com/shellinabox/shellinabox 
            ./shellinaboxd -t 启动软件:shellinbox -b 后台启动

 



posted @ 2018-05-27 14:43  你是我的神奇  阅读(249)  评论(0编辑  收藏  举报