Skip to main content

newssh

newssh 是一个轻量的 SSH 连接管理器。它可以读取已有的 SSH 配置,也可以为常用服务器保存独立配置;密码会在本机加密保存,连接时自动完成认证。

安装

需要 Python 3.10 或更高版本。推荐从 PyPI 安装:

python -m pip install newssh

Linux 和 WSL 连接时使用系统的 ssh 命令,请先安装 OpenSSH 客户端。Windows 使用 Paramiko,不需要额外安装 sshpassptytermios

快速开始

使用交互式菜单

直接运行 newssh,使用方向键选择连接:

  • Enter:连接当前服务器
  • ↑ / ↓:选择服务器
  • ← / →:切换页面
  • s:刷新当前页的端口可达状态
  • a:添加服务器
  • r:删除由 newssh 创建的服务器配置
  • q:退出
newssh

程序会读取本机 SSH 配置中的普通 Host 条目,以及 newssh 自己保存的配置。Linux/WSL 默认读取 ~/.ssh/config;Windows 默认读取 %USERPROFILE%\\.ssh\\config。带有 *!? 的通配 Host 条目不会作为独立连接显示。

使用命令行

添加配置时会隐藏密码输入:

newssh add prod --host 192.168.1.10 --user root
newssh list
newssh connect prod
newssh remove prod

如果同名配置已经存在,添加时需要显式指定 --force 才会覆盖:

newssh add prod --host 192.168.1.11 --user root --force

也可以指定端口和私钥。--no-password 表示不保存 SSH 密码;如果公钥认证失败,连接时仍会询问密码,但不会保存这次输入:

newssh add staging \
  --host example.com \
  --user deploy \
  --port 2222 \
  --identity ~/.ssh/id_ed25519 \
  --no-password

Windows PowerShell 中可使用相同命令;请把私钥路径改为 Windows 路径,例如 C:\\Users\\you\\.ssh\\id_ed25519

认证方式

连接时会优先尝试公钥认证,包括配置中指定的私钥、本机默认私钥和 ssh-agent。公钥认证失败后:

  • 如果配置中保存了密码,newssh 会自动尝试该密码;
  • 如果没有保存密码,newssh 会在终端中询问密码,并在成功后加密保存;
  • 如果使用了 --no-password,输入的密码不会保存。

首次连接服务器时,newssh 不会静默接受未知的 SSH 主机密钥。请先使用系统 SSH 客户端连接并核对指纹,将确认过的主机密钥写入 known_hosts 后再使用 newssh;Windows 也会读取 Paramiko/OpenSSH 可用的系统主机密钥,并拒绝未知主机。

数据和密码安全

默认情况下,newssh 在用户目录下创建 .newssh

  • profiles.json:服务器连接配置;
  • secrets.json:使用 Fernet 加密的密码;
  • master.key:用于解密密码的本机密钥。

可以通过 NEWSSH_DATA_DIR 指定其他数据目录:

NEWSSH_DATA_DIR=/path/to/newssh-data newssh

Windows PowerShell:

$env:NEWSSH_DATA_DIR = "C:\\Users\\you\\newssh-data"
newssh

newssh 不要求用户额外输入主密码,因此解密密钥也保存在本机。请保护好当前操作系统账户和数据目录;删除或丢失 master.key 后,已经保存的密码无法恢复。不要把 .newssh 目录提交到代码仓库或共享给其他用户。

常用命令

newssh                 打开交互式菜单
newssh add ...         添加配置
newssh list            列出配置(也可使用 ls)
newssh connect NAME    连接服务器(也可使用 c)
newssh remove NAME     删除配置(也可使用 rm)
newssh --help          查看帮助

Linux/WSL 下,connect 后的其他参数会继续传给系统 ssh,例如:

newssh connect prod -L 8080:localhost:8080

Windows 下使用 Paramiko 连接,目前不支持在 connect 后追加额外 SSH 参数;请把端口、用户名和私钥等信息写入配置。

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

newssh-0.1.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

newssh-0.1.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file newssh-0.1.0.tar.gz.

File metadata

  • Download URL: newssh-0.1.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.27.0 CPython/3.12.10 Windows/11

File hashes

Hashes for newssh-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2553720ec4260d806b12db4b1540566059db6a2606c5e0d33d94471d0f5fac79
MD5 7b40e63e9dc6065829ddbd7a66624256
BLAKE2b-256 879c7877fb2904611e0ccc34b8f93380b5c5875f2ee51d1f32e941f605e00e93

See more details on using hashes here.

File details

Details for the file newssh-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: newssh-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.27.0 CPython/3.12.10 Windows/11

File hashes

Hashes for newssh-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2572c9483af545d750d0e0f21e13f290a6fcee1abdf64b8a3f1cfc7b8157ac8b
MD5 44884b4f407c0a769c191fe8660ff632
BLAKE2b-256 21d3e2a7476feecaf4865c59bb1668ff46a8da9f6be05cdf003faa448a0ae94e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page