ssh扩展

sshx的Python项目详细描述


sshx(ssh扩展)

Build Statuscodecovlicense

sshx是ssh/scp命令的轻量级包装器,它具有以下功能:

  • 记住您的ssh帐户
  • 使用短命令连接到您的帐户,无需键入密码
  • 为您的连接启用跳转主机
  • 使用一个简短的命令创建ssh转发,无需键入密码
  • 为端口转发启用跳转主机
  • 使用简短的命令将文件从/复制到您的帐户,无需键入密码
  • 为您的SCP连接启用跳转主机

安装

从pypi安装

对于windows

pip install --extra-index-url https://wqyjh.github.io/python-wheels/ sshx

对于linuxmacos

pip install sshx

从源安装

对于windows

pip install --extra-index-url https://wqyjh.github.io/python-wheels/ git+https://github.com/WqyJh/sshx

# Or

pip install -i  https://wqyjh.github.io/python-wheels/ pyHook
python setup.py install

# Or

pip install -r requirements.txt

对于linuxmacox

pip install git+https://github.com/WqyJh/sshx

# Or

python setup.py install

# Or

pip install -r requirements.txt

快速启动

  1. 初始化。
sshx init
  1. 添加帐户。
sshx add myhost -l test@192.168.9.155

(此命令将要求您键入密码,SSHX将存储加密的密码。)

  1. 连接到帐户。
sshx connect myhost

用法

初始化

sshx init执行初始化。

它将自动创建以下存储帐户信息的文件。如果文件损坏了你可能会 丢失了所有帐户记录,因此不要触摸它。如果发生这种情况,请使用此命令重新初始化并使用 add命令重新添加它们。

$ sshx init
$ tree ~/.sshx
~/.sshx
└── .accounts

添加帐户

sshx add添加帐户。

# add an account in an simple way
sshx add myhost -l user@host:port

# add an account and specify an password for authentication
sshx add myhost -H host -P port -u user -p

# add an account and specify an identity file for authentication
sshx add myhost -H host -P port -u user -i identity_file

# add an account and specify both password and identity file for authentication
sshx add myhost -H host -P port -u user -p -i identity_file

# add an account named myhost2 and specify an password for authentication# use pre-added myhost as it's jump host
sshx add -l user@host:port -v myhost myhost2
  • 添加帐户需要主机和用户选项。
  • 添加帐户需要密码或标识选项。您还可以为帐户指定这两个选项。在这种情况下,只使用身份进行身份验证(以后可能会改进)。
  • 密码是从提示符输入的,不会显示在屏幕上。

显示帐户

sshx list按以下格式列出所有帐户。

name                host                          user                via                 
-----               -----                         -----               -----               
host1               192.168.7.1                   root                                    
host2               192.168.7.2                   test                host1               
host3               192.168.7.3                   root                host2               

删除帐户

sshx del删除一个帐户。

sshx del host1

更新帐户

sshx update更新帐户。

支持的选项与add命令相同,将更新所有指定的字段。

# change the host1's host field to domain.com
sshx update host1 -H domain.com

# change the host1's password
sshx update host1 -p

# change the host1's identity to identity2
sshx update host1 -i identity2

# TODO# change the host1's name to host2, and the next time you want to # change the account you have to use `sshx update host2 ...`#sshx update host1 -n host2

连接帐户

sshx connect连接到帐户。

# Connect to host1 directly.
sshx connect host1

# Connect to host1 using host2 as jump host.# If the host1 was originally has an jump host,# this argument would temporarily override it.
sshx connect host1 -v host2

# Connect to hsot1 using host2 as jump host,# while the host2 is using host3 as jump host.
sshx connect host1 -v host2,host3

注意如果使用-v选项,则所有帐户 VIA字段将被忽略。

创建端口转发

sshx forward创建端口保护。

sshx forward host1 [-f <map1> [map2]][-rf <rmap1> [rmap2]][-v host2[,host3]]

map: [bind_address]:bind_port:remote_address:remote_port

rmap: bind_address:bind_port:local_address:local_port

例如:

# Forward localhost:8888 to 192.168.77.7:80, # while the host1 is the intermedia server, # so you must ensure the host1 could dial to 192.168.77.7:80.
sshx forward host1 -f :8888:192.168.77.7:80
# Forward host1:8888 to 192.168.99.9:8888. # When you access localhost:8000 on host1, # the connection would be forward to 192.168.99.9:8888, # while your computer is working as a intermediate server # so you have to ensure your computer has access to 192.168.99.9:8888.
sshx forward host1 -r :8000:192.168.99.9:8888
  • 您可以同时使用-f-rf参数。
  • 也可以在-f-rf之后指定多个映射。
  • 可以使用-v选项将跳转主机指定为connect。

复制文件

sshx scp将文件复制到/从服务器复制文件。

# Copy local files to host1
sshx scp <src> host1:<dst>

# Copy remote files from host1 to local
sshx scp host1:<src> <dst>

# Copy local files to host1, using host2 as jump host
sshx scp <src> host1:<dst> -v host2

# Copy remote files to local, using host2 as jump host# and using host3 as host2's jump host.
sshx scp host1:<src> <dst> -v host2,host3

待办事项:

# Copy remote files from host1 to host2
sshx scp host1:<src> host2:<dst>

测试

python setup.py test

待办事项

  • [X]SCP支持
  • [X]跳转主机支持

错误

更改日志

[未发布]

新功能

  • 添加日志记录

错误修复

  • 删除指纹

管理和家务

  • 向pypi添加自动部署

版本0.3.0(2019-07-12)

新功能

  • 添加sshx forward命令
  • 添加SCP命令
  • 通过多个跳转主机添加连接

错误修复

  • 修复测试。测试连接

版本0.2.1(2019-06-23)

新功能

  • 为connect添加via参数

版本0.2.0(2019-06-23)

新功能

  • 为pexpect添加跳转连接
  • 在命令行中添加跳转主机

重构

  • 使用sshwrap中的帐户

版本0.1.0(2018-10-18)

新功能
  • 添加自动调整窗口大小
  • 为add命令的缩写添加测试

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Sonarqube测试覆盖率过滤器(jacoco)   java演示文稿将被取消,因为自创建以来显示度量已更改   java为什么Omnifaces Websocket<o:socket>不能与Websphere 9一起使用?   我试图读取java中的xml,但在我的系统中出现了一个错误   java异步支持未启用,即使默认情况下应该启用   java getThreadHandler方法无法从HandlerThread实例访问   带成员函数的多线程Java启动线程   java jar非法参数   java以编程方式注册@Component注释类   正则表达式如何在java中查找字符串中的长双精度数   具有多客户端的java ServerSocket   java JNI不适用于AppKit线程   java如何在用户选择目录元哈希值时输出该值?   java在春季上传阿拉伯文文件时,文件名以XML实体而不是阿拉伯文符号结束   java为什么我们需要在eclipse中作为远程服务器进行调试?   面向java的数据库计算PageRank   java在单击时切换到不同的活动