基于web的ssh客户端
webssh的Python项目详细描述
简介
一个简单的Web应用程序,用作连接到 ssh服务器。它是用python编写的,基于tornado、paramiko和 xterm.js.公司
功能
- 支持ssh密码验证,包括空密码。
- 支持ssh公钥身份验证,包括dsa rsa ecdsa ED25519键。
- 支持加密密钥。
- 支持双因素身份验证(基于时间的一次性密码)。
- 支持全屏终端。
- 可调整终端窗口大小。
- 自动检测ssh服务器的默认编码。
- 现代浏览器包括Chrome、Firefox、Safari、Edge、Opera 支持。
预览
工作原理
+---------+ http +--------+ ssh +-----------+ | browser | <==========> | webssh | <=======> | ssh server| +---------+ websocket +--------+ ssh +-----------+
要求
- Python2.7/3.4+
快速启动
- 安装此应用程序,运行命令pip install webssh
- 启动web服务器,运行命令wssh
- 打开浏览器,导航到127.0.0.1:8888
- 输入你的数据,提交表格。
服务器选项
# start a http server with specified listen address and listen port wssh --address='2.2.2.2' --port=8000# start a https server, certfile and keyfile must be passed wssh --certfile='/path/to/cert.crt' --keyfile='/path/to/cert.key'# missing host key policy wssh --policy=reject # logging level wssh --logging=debug # log to file wssh --log-file-prefix=main.log # more options wssh --help
浏览器控制台
// connect to your ssh server wssh.connect(hostname,port,username,password,privatekey,passphrase,totp);// pass an object to wssh.connect varopts={hostname:'hostname',port:'port',username:'username',password:'password',privatekey:'the private key text',passphrase:'passphrase',totp:'totp'};wssh.connect(opts);// without an argument, wssh will use the form data to connect wssh.connect();// set a new encoding for client to use wssh.set_encoding(encoding);// reset encoding to use the default one wssh.reset_encoding();// send a command to the server wssh.send('ls -l');
自定义字体
自定义字体系列用法示例:
<style>@font-face{font-family:'font-name';src:url('static/css/fonts/your-favorite-font');}body{font-family:'font-name';}</style>
url参数
支持按url(查询或片段)传递参数,如下所示 示例:
传递表单数据(密码必须以base64编码,privateKey不能 支持)
http://localhost:8888/?hostname=xx&username=yy&password=str_base64_encoded
传递终端背景色
http://localhost:8888/#bgcolor=green
传递用户定义的标题
http://localhost:8888/?title=my-ssh-server
传递编码
http://localhost:8888/#encoding=gbk
传递登录后立即执行的命令
http://localhost:8888/?command=pwd
使用Docker
启动应用程序
docker-compose up
关闭应用程序
docker-compose down
测试
要求
pip install pytest pytest-cov codecov flake8 mock
使用unittest运行所有测试
python -m unittest discover tests
使用pytest运行所有测试
python -m pytest tests
展开
在nginx服务器后面运行
wssh --address='127.0.0.1' --port=8888 --policy=reject
# Nginx config example location/{proxy_passhttp://127.0.0.1:8888;proxy_http_version1.1;proxy_read_timeout300;proxy_set_headerUpgrade$http_upgrade;proxy_set_headerConnection"upgrade";proxy_set_headerHost$http_host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Real-PORT$remote_port;}
作为独立服务器运行
wssh --port=8080 --sslport=4433 --certfile='cert.crt' --keyfile='cert.key' --xheaders=False --policy=reject
提示
- 对于您选择的任何部署选择,不要忘记启用 SSL协议。
- 默认情况下,来自公共网络的纯http请求将是 重定向或被阻止和被重定向优先于 被封锁了。
- 尝试将拒绝策略与 你的已知主机,这将防止中间人 攻击。其思想是检查系统主机密钥 文件(“~/.ssh/known_hosts”)和应用程序主机密钥 如果ssh服务器的主机名不是 找到或密钥不匹配,连接将中止。