增强 SSH
ssh连接管理工具 项目背景: 方便管理 ssh 连接,降低登录服务器的成本 使用场景:
- 管理 ssh 账号、密码、秘钥等配置
- 一键登录服务器
- 基于 expect 指令进行额外操作(e.g. 通过跳板机登录运维机)
使用说明
如何安装该项目
本项目使用 poetry 管理依赖和打包, 目前该项目以发布至 pypi.org, 你可以从 pypi.org 安装该依赖或者选择从源码进行安装。
从 pypi.org 安装该应用
1. 安装
p.s. 推荐使用 pipx 管理基于 pip 安装的命令
#!/usr/bin/env bash
## 简单安装
pip install ssh-mgr -i https://pypi.org/simple/
## 使用 pipx 安装
pipx install ssh-mgr -i https://pypi.org/simple/
## 加载 ssh2_wrapper.sh 内置的指令
source $(ssh2 get-wrapper-dot-sh)
2. 使用
- 使用(demo)
# file `demo.yml`
## Create with a nested object
kind: Session
spec:
tag: session-1
name: unique_name_to_mark_this_session_1
plugins:
- kind: SSH_LOGIN
args:
client:
spec:
user: username_whose_login_to_server
name: unique_name_to_mark_this_client_1
auth:
spec:
name: unique_name_to_mark_this_auth_1
type: PASSWORD
content: your_password
expect_for_password: str
server:
spec:
name: unique_name_to_mark_this_server_1
host: host_of_server
port: port_of_server
---
# Create with multi object
kind: ClientConfig
spec:
name: unique_name_to_mark_this_client_2
user: username_whose_login_to_server
auth:
spec:
name: unique_name_to_mark_this_auth_2
type: INTERACTIVE_PASSWORD
content: 'a placeholder'
---
kind: ServerConfig
spec:
name: unique_name_to_mark_this_server_2
host: host_of_server
port: port_of_server
---
kind: Session
spec:
tag: session-2
name: unique_name_to_mark_this_session_2
plugins:
- kind: SSH_WETERM
args:
client:
ref:
field: name
value: unique_name_to_mark_this_client_2
server:
ref:
field: name
value: unique_name_to_mark_this_server_2
ssh2 create -f demo.yml
go2s
# show `session-1 session-2`
go2s session-1
# try login to session-1
从源码安装该应用
1. 请根据 官方文档 安装 poetry
2. 下载源码
#!/usr/bin/env bash
git clone github https://github.com/shabbywu/ssh2.git
3. 使用 poetry 打包项目
#!/usr/bin/env bash
# 假设你刚执行完 git clone
cd ssh2
poetry build
4. 安装
p.s. 推荐使用 pipx 管理基于 pip 安装的命令
#!/usr/bin/env bash
# 假设你刚执行 poetry build
cd dist
## 简单使用
pip install ssh2-0.1.1.tar.gz
## 使用 pipx
pipx install ssh2-0.1.1.tar.gz
## 加载 ssh2_wrapper.sh 内置的指令
bash
source $(ssh2 get-wrapper-dot-sh)
5. 使用(demo)
# file `demo.yml`
## Create with a nested object
kind: Session
spec:
tag: session-1
name: unique_name_to_mark_this_session_1
plugins:
- kind: SSH_LOGIN
args:
client:
spec:
user: username_whose_login_to_server
name: unique_name_to_mark_this_client_1
auth:
spec:
name: unique_name_to_mark_this_auth_1
type: PASSWORD
content: your_password
expect_for_password: str
server:
spec:
name: unique_name_to_mark_this_server_1
host: host_of_server
port: port_of_server
---
# Create with multi object
kind: ClientConfig
spec:
name: unique_name_to_mark_this_client_2
user: username_whose_login_to_server
auth:
spec:
name: unique_name_to_mark_this_auth_2
type: INTERACTIVE_PASSWORD
content: 'a placeholder'
---
kind: ServerConfig
spec:
name: unique_name_to_mark_this_server_2
host: host_of_server
port: port_of_server
---
kind: Session
spec:
tag: session-2
name: unique_name_to_mark_this_session_2
plugins:
- kind: SSH_WETERM
args:
client:
ref:
field: name
value: unique_name_to_mark_this_client_2
server:
ref:
field: name
value: unique_name_to_mark_this_server_2
ssh2 create -f demo.yml
go2s
# show `session-1 session-2`
go2s session-1
# try login to session-1
附录
数据结构
---
kind: AuthMethod
spec:
name: str | nullable
type: str
content: str
expect_for_password: str
save_private_key_in_db: bool
---
kind: ClientConfig
spec:
user: str
name: str | nullable
auth:
ref:
field: id/name
value: int/str
spec:
name: str | nullable
type: str
content: str
expect_for_password: str
save_private_key_in_db: bool
---
kind: ServerConfig
spec:
name: str
host: str
port: int
---
kind: Session
spec:
tag: str
name: str
plugins:
- kind: SSH_LOGIN
args:
- kind: EXPECT
args:
expect: str
send: str
raw:
- str
- str
- str
client:
ref:
field: id/name
value: int/str
spec:
user: str
name: str | nullable
auth:
ref:
field: id/name
value: int/str
spec:
name: str | nullable
type: str
content: password
expect_for_password: str
save_private_key_in_db: bool
server:
ref:
field: id/name
value: int/str
spec:
name: str
host: str
port: int
项目建模:
AuthMethod: 连接服务器时, 进行身份验证的方法(PASSWORD、PUBLISH_KEY等)
ClientConfig: 连接服务器时, 使用的身份信息(username), 关联着 AuthMethod
ServerConfig: 连接的服务器信息, 包括(host、port)
Session: ssh会话配置, 描述了使用哪个ClientConfig连接哪个ServerConfig的信息
项目整体结构:
+--------------------+
+-------------+ +-------------+ | +--------------+ |
| config.yaml | --+-- | config.yaml | | | | |
+-------------+ | +-------------+ | | AuthMethod | |
| | | | |
| | +-------+------+ |
v | ^ |
+-----+------+ | v |
cretae/update | | | +-------+------+ |
+----------------->+ YamlParser | | | | |
| | | | | ClientConfig | |
| +-----+------+ | | | |
| | | +-------+------+ |
| | | | |
| v | | |
+-----------------+ +----+--------+ +-----+-------+ +----------+ | +-----+---+ |
| | invoke | | read | | | | | | | |
| shell-wrapper +-------->+ Click-cli +-------->+ sqlalchemy +---------->+ models | | | Session | |
| | | | | | | | | | | |
+-----+-----------+ +-------------+ +-------------+ +----------+ | +-----+---+ |
^ | | |
| | | |
| +-------------+ | +-------+------+ |
| eval +-----------+ generate | | bind | | | |
+--------------------+ | expect.sh | <----+ | plugins +<----------------------------+ ServerConfig | |
+-----------+ | | | | | |
.. +-------------+ | +--------------+ |
.. | | | |
+-----------+ | *SSH_LOGIN | +--------------------+
| expect.sh | | |
+-----------+ | *SSH_WETERM |
.. | |
.. | *EXPECT |
.. | |
.. +-------------+
+-----------+
| expect.sh |
+-----------+
Metadata
Release files for ssh-mgr 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ssh_mgr-1.1.1.tar.gz | 14.5 kB | Without provenance | Details for ssh_mgr-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ssh_mgr-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for ssh_mgr-1.1.1-py3-none-any.whl |
Total release size: 32.9 kB
Release files / ssh_mgr-1.1.1.tar.gz
| Download URL | ssh_mgr-1.1.1.tar.gz |
|---|---|
| Size | 14.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
249b0ca64982544b3a8f87d2a9cfb70813afc7d365b3a87758f7b8af5ca41d17
|
|
BLAKE2b-256 checksum How to use checksums |
fa792d939a95a61a6fbae02a347760198150d35b748647d467fe5ca26a6db2b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.11.9 Windows/10
|
Release files / ssh_mgr-1.1.1-py3-none-any.whl
| Download URL | ssh_mgr-1.1.1-py3-none-any.whl |
|---|---|
| Size | 18.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df4c4f3e147b5aa7a08486a9448683fa3c200f5a2d8b873c833822fae4481044
|
|
BLAKE2b-256 checksum How to use checksums |
b6080f6bf304e55ad05db2c453e81f92c582eb0bfa8c3d45bef4afc0109fed10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.11.9 Windows/10
|
Security for ssh-mgr 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.