ssh-mgr


Namessh-mgr JSON
Version 1.1.1 PyPI version JSON
download
home_pageNone
SummaryA Tool to manage ssh connection
upload_time2024-08-26 15:03:49
maintainerNone
docs_urlNone
authorshabbywu
requires_python<4.0,>=3.8
licenseMIT
keywords ssh
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 增强 SSH
ssh连接管理工具
项目背景: 方便管理 ssh 连接,降低登录服务器的成本
使用场景:
-   管理 ssh 账号、密码、秘钥等配置
-   一键登录服务器
-   基于 expect 指令进行额外操作(e.g. 通过跳板机登录运维机)

## 使用说明
### 如何安装该项目
本项目使用 [poetry](https://python-poetry.org/) 管理依赖和打包, 目前该项目以发布至 pypi.org, 你可以从 pypi.org 安装该依赖或者选择从源码进行安装。

#### 从 pypi.org 安装该应用
##### 1. 安装
p.s. 推荐使用 [pipx](https://pipxproject.github.io/pipx/) 管理基于 pip 安装的命令
```bash
#!/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. 使用
5. 使用(demo)
```yml
# 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
```
```bash
ssh2 create -f demo.yml
go2s
# show `session-1 session-2`
go2s session-1
# try login to session-1
```

#### 从源码安装该应用
##### 1. 请根据 [官方文档](https://python-poetry.org/docs/#installation) 安装 poetry
##### 2. 下载源码
```bash
#!/usr/bin/env bash
git clone github https://github.com/shabbywu/ssh2.git
```
##### 3. 使用 poetry 打包项目
```bash
#!/usr/bin/env bash
# 假设你刚执行完 git clone
cd ssh2
poetry build
```
##### 4. 安装   
p.s. 推荐使用 [pipx](https://pipxproject.github.io/pipx/) 管理基于 pip 安装的命令
```bash
#!/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)
```yml
# 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
```
```bash
ssh2 create -f demo.yml
go2s
# show `session-1 session-2`
go2s session-1
# try login to session-1
```
## 附录
### 数据结构
```yaml
---
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的信息   
项目整体结构:
```text
                                                                                             +--------------------+
                                        +-------------+       +-------------+                |  +--------------+  |
                                        | 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 |
                             +-----------+

```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ssh-mgr",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "ssh",
    "author": "shabbywu",
    "author_email": "shabbywu@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/fa/79/2d939a95a61a6fbae02a347760198150d35b748647d467fe5ca26a6db2b3/ssh_mgr-1.1.1.tar.gz",
    "platform": null,
    "description": "# \u589e\u5f3a SSH\nssh\u8fde\u63a5\u7ba1\u7406\u5de5\u5177\n\u9879\u76ee\u80cc\u666f: \u65b9\u4fbf\u7ba1\u7406 ssh \u8fde\u63a5\uff0c\u964d\u4f4e\u767b\u5f55\u670d\u52a1\u5668\u7684\u6210\u672c\n\u4f7f\u7528\u573a\u666f:\n-   \u7ba1\u7406 ssh \u8d26\u53f7\u3001\u5bc6\u7801\u3001\u79d8\u94a5\u7b49\u914d\u7f6e\n-   \u4e00\u952e\u767b\u5f55\u670d\u52a1\u5668\n-   \u57fa\u4e8e expect \u6307\u4ee4\u8fdb\u884c\u989d\u5916\u64cd\u4f5c(e.g. \u901a\u8fc7\u8df3\u677f\u673a\u767b\u5f55\u8fd0\u7ef4\u673a)\n\n## \u4f7f\u7528\u8bf4\u660e\n### \u5982\u4f55\u5b89\u88c5\u8be5\u9879\u76ee\n\u672c\u9879\u76ee\u4f7f\u7528 [poetry](https://python-poetry.org/) \u7ba1\u7406\u4f9d\u8d56\u548c\u6253\u5305, \u76ee\u524d\u8be5\u9879\u76ee\u4ee5\u53d1\u5e03\u81f3 pypi.org, \u4f60\u53ef\u4ee5\u4ece pypi.org \u5b89\u88c5\u8be5\u4f9d\u8d56\u6216\u8005\u9009\u62e9\u4ece\u6e90\u7801\u8fdb\u884c\u5b89\u88c5\u3002\n\n#### \u4ece pypi.org \u5b89\u88c5\u8be5\u5e94\u7528\n##### 1. \u5b89\u88c5\np.s. \u63a8\u8350\u4f7f\u7528 [pipx](https://pipxproject.github.io/pipx/) \u7ba1\u7406\u57fa\u4e8e pip \u5b89\u88c5\u7684\u547d\u4ee4\n```bash\n#!/usr/bin/env bash\n## \u7b80\u5355\u5b89\u88c5\npip install ssh-mgr -i https://pypi.org/simple/\n## \u4f7f\u7528 pipx \u5b89\u88c5\npipx install ssh-mgr -i https://pypi.org/simple/\n\n## \u52a0\u8f7d ssh2_wrapper.sh \u5185\u7f6e\u7684\u6307\u4ee4\nsource $(ssh2 get-wrapper-dot-sh)\n```\n\n##### 2. \u4f7f\u7528\n5. \u4f7f\u7528(demo)\n```yml\n# file `demo.yml`\n## Create with a nested object\nkind: Session\nspec:\n    tag: session-1\n    name: unique_name_to_mark_this_session_1\n    plugins:\n        -   kind:   SSH_LOGIN\n            args:\n    client:\n        spec:\n            user: username_whose_login_to_server\n            name: unique_name_to_mark_this_client_1\n            auth:\n                spec:\n                    name: unique_name_to_mark_this_auth_1\n                    type: PASSWORD\n                    content: your_password\n                    expect_for_password: str\n    server:\n        spec:\n            name: unique_name_to_mark_this_server_1\n            host: host_of_server\n            port: port_of_server\n---\n# Create with multi object\nkind: ClientConfig\nspec:\n  name: unique_name_to_mark_this_client_2\n  user: username_whose_login_to_server\n  auth:\n    spec:\n      name: unique_name_to_mark_this_auth_2\n      type: INTERACTIVE_PASSWORD\n      content: 'a placeholder'\n---\nkind: ServerConfig\nspec:\n  name: unique_name_to_mark_this_server_2\n  host: host_of_server\n  port: port_of_server\n---\nkind: Session\nspec:\n    tag: session-2\n    name: unique_name_to_mark_this_session_2\n    plugins:\n        -   kind:   SSH_WETERM\n            args:\n    client:\n      ref:\n        field: name\n        value: unique_name_to_mark_this_client_2\n    server:\n      ref:\n        field: name\n        value: unique_name_to_mark_this_server_2\n```\n```bash\nssh2 create -f demo.yml\ngo2s\n# show `session-1 session-2`\ngo2s session-1\n# try login to session-1\n```\n\n#### \u4ece\u6e90\u7801\u5b89\u88c5\u8be5\u5e94\u7528\n##### 1. \u8bf7\u6839\u636e [\u5b98\u65b9\u6587\u6863](https://python-poetry.org/docs/#installation) \u5b89\u88c5 poetry\n##### 2. \u4e0b\u8f7d\u6e90\u7801\n```bash\n#!/usr/bin/env bash\ngit clone github https://github.com/shabbywu/ssh2.git\n```\n##### 3. \u4f7f\u7528 poetry \u6253\u5305\u9879\u76ee\n```bash\n#!/usr/bin/env bash\n# \u5047\u8bbe\u4f60\u521a\u6267\u884c\u5b8c git clone\ncd ssh2\npoetry build\n```\n##### 4. \u5b89\u88c5   \np.s. \u63a8\u8350\u4f7f\u7528 [pipx](https://pipxproject.github.io/pipx/) \u7ba1\u7406\u57fa\u4e8e pip \u5b89\u88c5\u7684\u547d\u4ee4\n```bash\n#!/usr/bin/env bash\n# \u5047\u8bbe\u4f60\u521a\u6267\u884c poetry build\ncd dist\n## \u7b80\u5355\u4f7f\u7528\npip install ssh2-0.1.1.tar.gz\n## \u4f7f\u7528 pipx\npipx install ssh2-0.1.1.tar.gz\n\n## \u52a0\u8f7d ssh2_wrapper.sh \u5185\u7f6e\u7684\u6307\u4ee4\nbash\nsource $(ssh2 get-wrapper-dot-sh)\n```\n##### 5. \u4f7f\u7528(demo)\n```yml\n# file `demo.yml`\n## Create with a nested object\nkind: Session\nspec:\n    tag: session-1\n    name: unique_name_to_mark_this_session_1\n    plugins:\n        -   kind:   SSH_LOGIN\n            args:\n    client:\n        spec:\n            user: username_whose_login_to_server\n            name: unique_name_to_mark_this_client_1\n            auth:\n                spec:\n                    name: unique_name_to_mark_this_auth_1\n                    type: PASSWORD\n                    content: your_password\n                    expect_for_password: str\n    server:\n        spec:\n            name: unique_name_to_mark_this_server_1\n            host: host_of_server\n            port: port_of_server\n---\n# Create with multi object\nkind: ClientConfig\nspec:\n  name: unique_name_to_mark_this_client_2\n  user: username_whose_login_to_server\n  auth:\n    spec:\n      name: unique_name_to_mark_this_auth_2\n      type: INTERACTIVE_PASSWORD\n      content: 'a placeholder'\n---\nkind: ServerConfig\nspec:\n  name: unique_name_to_mark_this_server_2\n  host: host_of_server\n  port: port_of_server\n---\nkind: Session\nspec:\n    tag: session-2\n    name: unique_name_to_mark_this_session_2\n    plugins:\n        -   kind:   SSH_WETERM\n            args:\n    client:\n      ref:\n        field: name\n        value: unique_name_to_mark_this_client_2\n    server:\n      ref:\n        field: name\n        value: unique_name_to_mark_this_server_2\n```\n```bash\nssh2 create -f demo.yml\ngo2s\n# show `session-1 session-2`\ngo2s session-1\n# try login to session-1\n```\n## \u9644\u5f55\n### \u6570\u636e\u7ed3\u6784\n```yaml\n---\nkind: AuthMethod\nspec:\n    name: str | nullable\n    type: str\n    content: str\n    expect_for_password: str\n    save_private_key_in_db: bool\n---\nkind: ClientConfig\nspec:\n    user: str\n    name: str | nullable\n    auth:\n        ref:\n            field: id/name\n            value: int/str\n        spec:\n            name: str | nullable\n            type: str\n            content: str\n            expect_for_password: str\n            save_private_key_in_db: bool\n---\nkind: ServerConfig\nspec:\n    name: str\n    host: str\n    port: int\n\n---\nkind: Session\nspec:\n    tag: str\n    name: str\n    plugins:\n        -   kind:   SSH_LOGIN\n            args:\n        -   kind:   EXPECT\n            args:\n                expect: str\n                send:   str\n                raw:\n                -   str\n                -   str\n                -   str\n    client:\n        ref:\n            field: id/name\n            value: int/str\n        spec:\n            user: str\n            name: str | nullable\n            auth:\n                ref:\n                    field: id/name\n                    value: int/str\n                spec:\n                    name: str | nullable\n                    type: str\n                    content: password\n                    expect_for_password: str\n                    save_private_key_in_db: bool\n    server:\n        ref:\n            field: id/name\n            value: int/str\n        spec:\n            name: str\n            host: str\n            port: int\n```\n### \u9879\u76ee\u5efa\u6a21:\n**AuthMethod**: \u8fde\u63a5\u670d\u52a1\u5668\u65f6, \u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\u7684\u65b9\u6cd5(PASSWORD\u3001PUBLISH_KEY\u7b49)   \n**ClientConfig**: \u8fde\u63a5\u670d\u52a1\u5668\u65f6, \u4f7f\u7528\u7684\u8eab\u4efd\u4fe1\u606f(username), \u5173\u8054\u7740 AuthMethod   \n**ServerConfig**: \u8fde\u63a5\u7684\u670d\u52a1\u5668\u4fe1\u606f, \u5305\u62ec(host\u3001port)   \n**Session**: ssh\u4f1a\u8bdd\u914d\u7f6e, \u63cf\u8ff0\u4e86\u4f7f\u7528\u54ea\u4e2aClientConfig\u8fde\u63a5\u54ea\u4e2aServerConfig\u7684\u4fe1\u606f   \n\u9879\u76ee\u6574\u4f53\u7ed3\u6784:\n```text\n                                                                                             +--------------------+\n                                        +-------------+       +-------------+                |  +--------------+  |\n                                        | config.yaml | --+-- | config.yaml |                |  |              |  |\n                                        +-------------+   |   +-------------+                |  |  AuthMethod  |  |\n                                                          |                                  |  |              |  |\n                                                          |                                  |  +-------+------+  |\n                                                          v                                  |          ^         |\n                                                    +-----+------+                           |          v         |\n                                    cretae/update   |            |                           |  +-------+------+  |\n                                 +----------------->+ YamlParser |                           |  |              |  |\n                                 |                  |            |                           |  | ClientConfig |  |\n                                 |                  +-----+------+                           |  |              |  |\n                                 |                        |                                  |  +-------+------+  |\n                                 |                        |                                  |          |         |\n                                 |                        v                                  |          |         |\n+-----------------+         +----+--------+         +-----+-------+           +----------+   |    +-----+---+     |\n|                 | invoke  |             |  read   |             |           |          |   |    |         |     |\n|  shell-wrapper  +-------->+  Click-cli  +-------->+ sqlalchemy  +---------->+  models  |   |    | Session |     |\n|                 |         |             |         |             |           |          |   |    |         |     |\n+-----+-----------+         +-------------+         +-------------+           +----------+   |    +-----+---+     |\n      ^                                                                                      |          |         |\n      |                                                                                      |          |         |\n      |                                             +-------------+                          |  +-------+------+  |\n      |    eval              +-----------+ generate |             |           bind           |  |              |  |\n      +--------------------+ | expect.sh |  <----+  |   plugins   +<----------------------------+ ServerConfig |  |\n                             +-----------+          |             |                          |  |              |  |\n                                  ..                +-------------+                          |  +--------------+  |\n                                  ..                |             |                          |                    |\n                             +-----------+          | *SSH_LOGIN  |                          +--------------------+\n                             | expect.sh |          |             |\n                             +-----------+          | *SSH_WETERM |\n                                  ..                |             |\n                                  ..                | *EXPECT     |\n                                  ..                |             |\n                                  ..                +-------------+\n                             +-----------+\n                             | expect.sh |\n                             +-----------+\n\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Tool to manage ssh connection",
    "version": "1.1.1",
    "project_urls": null,
    "split_keywords": [
        "ssh"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b6080f6bf304e55ad05db2c453e81f92c582eb0bfa8c3d45bef4afc0109fed10",
                "md5": "5b26168b871fead894d0cb9c7196e7e4",
                "sha256": "df4c4f3e147b5aa7a08486a9448683fa3c200f5a2d8b873c833822fae4481044"
            },
            "downloads": -1,
            "filename": "ssh_mgr-1.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5b26168b871fead894d0cb9c7196e7e4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 18353,
            "upload_time": "2024-08-26T15:03:48",
            "upload_time_iso_8601": "2024-08-26T15:03:48.228190Z",
            "url": "https://files.pythonhosted.org/packages/b6/08/0f6bf304e55ad05db2c453e81f92c582eb0bfa8c3d45bef4afc0109fed10/ssh_mgr-1.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fa792d939a95a61a6fbae02a347760198150d35b748647d467fe5ca26a6db2b3",
                "md5": "8531d4115d53154ba1fe0af9b9c6ad67",
                "sha256": "249b0ca64982544b3a8f87d2a9cfb70813afc7d365b3a87758f7b8af5ca41d17"
            },
            "downloads": -1,
            "filename": "ssh_mgr-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8531d4115d53154ba1fe0af9b9c6ad67",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 14525,
            "upload_time": "2024-08-26T15:03:49",
            "upload_time_iso_8601": "2024-08-26T15:03:49.333693Z",
            "url": "https://files.pythonhosted.org/packages/fa/79/2d939a95a61a6fbae02a347760198150d35b748647d467fe5ca26a6db2b3/ssh_mgr-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-26 15:03:49",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "ssh-mgr"
}
        
Elapsed time: 0.42074s