From 85ec2226e68c37cf8ba12045ab9fcfa467c5844f Mon Sep 17 00:00:00 2001 From: Lonny Wong Date: Tue, 2 Jan 2024 23:56:30 +0800 Subject: [PATCH] update readme --- README.cn.md | 526 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.en.md | 525 ++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 461 ++++++-------------------------------------- 3 files changed, 1114 insertions(+), 398 deletions(-) create mode 100644 README.cn.md create mode 100644 README.en.md diff --git a/README.cn.md b/README.cn.md new file mode 100644 index 0000000..5809fa2 --- /dev/null +++ b/README.cn.md @@ -0,0 +1,526 @@ +# trzsz-ssh ( tssh ) + +支持 [trzsz](https://trzsz.github.io/cn/) ( trz / tsz ) 的 ssh 客户端,支持搜索和选择服务器进行批量登录,支持记住密码。 + +Website: [https://trzsz.github.io/ssh](https://trzsz.github.io/ssh) ( English )  中文文档:[https://trzsz.github.io/cn/ssh](https://trzsz.github.io/cn/ssh) + +[![MIT License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://choosealicense.com/licenses/mit/) +[![GitHub Release](https://img.shields.io/github/v/release/trzsz/trzsz-ssh)](https://github.com/trzsz/trzsz-ssh/releases) + +## tssh 简介 + +- 你喜欢的 ssh 终端是否有好用的服务器管理功能?是否支持记住密码?是否有好用的文件传输工具? + +- tssh 支持选择或搜索 `~/.ssh/config` 中配置的服务器,支持 vim 操作习惯,解决 ssh 终端的服务器管理问题。 + +- tssh 支持一次选择多台服务器,批量登录,并支持批量执行预先指定的命令,方便快速完成批量服务器操作。 + +- tssh 支持配置服务器登录密码,解决每次手工输入密码的麻烦( 自己能控制的服务器,推荐使用公钥登录 )。 + +- tssh 内置支持 [trzsz](https://trzsz.github.io/cn/) ( trz / tsz ) 文件传输工具,一并解决了 Windows 中使用 `trzsz ssh` 上传速度很慢的问题。 + +- _在作者的 MacOS 上,使用 `trzsz ssh` 的上传速度在 10 MB/s 左右,而使用 `tssh` 可以到 80 MB/s 以上。_ + +## 安装方法 + +**_客户端安装 `trzsz-ssh ( tssh )` 的方法如下( 任选其一 ):_** + +- Windows 可用 [scoop](https://scoop.sh/) / [winget](https://learn.microsoft.com/zh-cn/windows/package-manager/winget/) / [choco](https://community.chocolatey.org/) 安装 + +
scoop install tssh / winget install tssh / choco install tssh + + ```sh + scoop install tssh + ``` + + ```sh + winget install tssh + ``` + + ```sh + choco install tssh + ``` + +
+ +- MacOS 可用 [homebrew](https://brew.sh/) 安装 + +
brew install trzsz-ssh + + ```sh + brew update + brew install trzsz-ssh + ``` + +
+ +- Ubuntu 可用 apt 安装 + +
sudo apt install tssh + + ```sh + sudo apt update && sudo apt install software-properties-common + sudo add-apt-repository ppa:trzsz/ppa && sudo apt update + + sudo apt install tssh + ``` + +
+ +- Debian 可用 apt 安装 + +
sudo apt install tssh + + ```sh + sudo apt install curl gpg + curl -s 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x7074ce75da7cc691c1ae1a7c7e51d1ad956055ca' \ + | gpg --dearmor -o /usr/share/keyrings/trzsz.gpg + echo 'deb [signed-by=/usr/share/keyrings/trzsz.gpg] https://ppa.launchpadcontent.net/trzsz/ppa/ubuntu jammy main' \ + | sudo tee /etc/apt/sources.list.d/trzsz.list + sudo apt update + + sudo apt install tssh + ``` + +
+ +- Linux 可用 yum 安装 + +
sudo yum install tssh + + - 国内推荐使用 [wlnmp](https://www.wlnmp.com/install) 源,安装 tssh 只需要添加 wlnmp 源( 配置 epel 源不是必须的 ): + + ```sh + curl -fsSL "https://sh.wlnmp.com/wlnmp.sh" | bash + + sudo yum install tssh + ``` + + - 也可使用 [gemfury](https://gemfury.com/) 源( 只要网络通,所有操作系统通用 ) + + ```sh + echo '[trzsz] + name=Trzsz Repo + baseurl=https://yum.fury.io/trzsz/ + enabled=1 + gpgcheck=0' | sudo tee /etc/yum.repos.d/trzsz.repo + + sudo yum install tssh + ``` + +
+ +- ArchLinux 可用 [yay](https://github.com/Jguer/yay) 安装 + +
yay -S tssh + + ```sh + yay -Syu + yay -S tssh + ``` + +
+ +- 用 Go 直接安装( 要求 go 1.20 以上 ) + +
go install github.com/trzsz/trzsz-ssh/cmd/tssh@latest + + ```sh + go install github.com/trzsz/trzsz-ssh/cmd/tssh@latest + ``` + + 安装后,`tssh` 程序一般位于 `~/go/bin/` 目录下( Windows 一般在 `C:\Users\your_name\go\bin\` )。 + +
+ +- 用 Go 自己编译( 要求 go 1.20 以上 ) + +
sudo make install + + ```sh + git clone --depth 1 https://github.com/trzsz/trzsz-ssh.git + cd trzsz-ssh + make + sudo make install + ``` + +
+ +- 可从 [Releases](https://github.com/trzsz/trzsz-ssh/releases) 中直接下载适用的版本 + +**_服务器上要安装 [trzsz](https://trzsz.github.io/cn/) 才能使用 `trz / tsz` 上传和下载,可任选其一安装: +[Go 版](https://trzsz.github.io/cn/go)( ⭐ 推荐 )、[Py 版](https://trzsz.github.io/cn/)、[Js 版](https://trzsz.github.io/cn/js)。_** + +_如果服务器不安装 [trzsz](https://trzsz.github.io/cn/),也能用 `tssh`,只是不使用 `trz / tsz` 上传和下载而已。_ + +## 使用方法 + +_`~/` 代表 HOME 目录。在 Windows 中,请将下文的 `~/` 替换成 `C:\Users\your_name\`。_ + +- 在客户端生成密钥对,一般存放在 `~/.ssh/` 下( 只要一种就可以了 ): + + - `ssh-keygen -t ed25519` 生成 ED25519 的,私钥 `~/.ssh/id_ed25519`,公钥 `~/.ssh/id_ed25519.pub`。 + - `ssh-keygen -t rsa -b 4096` 生成 RSA 的,私钥 `~/.ssh/id_rsa`,公钥 `~/.ssh/id_rsa.pub`。 + +- 登录服务器,将公钥( 即前面生成密钥对时 `.pub` 后缀的文件内容 )追加写入服务器上的 `~/.ssh/authorized_keys` 文件中。 + + - 一行代表一个客户端的公钥,注意 `~/.ssh/authorized_keys` 要设置正确的权限: + + ```sh + chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys + ``` + +- 在客户端配置好 `~/.ssh/config` 文件,举例: + + ``` + Host alias1 + HostName 192.168.0.1 + Port 22 + User your_name + Host alias2 + HostName 192.168.0.2 + Port 22 + User your_name + ``` + +- 使用 `tssh` 命令登录服务器,`tssh alias1` 命令登录在 `~/.ssh/config` 中 `alias1` 对应的服务器。 + +- 直接执行 `tssh` 命令( 不带参数 ),可以选择( 搜索 ) `~/.ssh/config` 中配置好的服务器并登录。 + +## 批量登录 + +- 支持在 `iTerm2`( 要开启 [Python API](https://iterm2.com/python-api-auth.html),但不需要`Allow all apps to connect` ),`tmux` 和 `Windows Terminal` 中一次选择多台服务器,批量登录,并支持批量执行预先指定的命令。 + +- 按下 `Space`、`Ctrl+X` 等可以选中或取消当前服务器,若不能选中说明还不支持当前终端,请先运行 `tmux`。 + +- 按下 `Ctrl+P` 会以分屏的方式批量登录,`Ctrl+W` 会打开新窗口批量登录,`Ctrl+T` 会打开新 tab 批量登录。 + +- `tssh` 不带参数启动可以批量登录服务器,若带 `-o RemoteCommand` 参数启动则可以批量执行指定的命令。支持执行指定命令之后进入交互式 shell,但 `Windows Terminal` 不支持分号 `;`,可以用 `|cat&&` 代替。举例: + + ```sh + tssh -t -o RemoteCommand='ping -c3 trzsz.github.io ; bash' + tssh -t -o RemoteCommand="ping -c3 trzsz.github.io |cat&& bash" + ``` + +## 分组标签 + +- 如果服务器数量很多,分组标签 `GroupLabels` 可以在按 `/` 搜索时,快速找到目标服务器。 + +- 按 `/` 输入分组标签后,`回车`可以锁定;再按 `/` 可以输入另一个分组标签,`回车`再次锁定。 + +- 在非搜索模式下,按 `E` 可以清空当前搜索标签;在搜索模式下按 `Ctrl + E` 也是同样效果。 + +- 支持在一个 `GroupLabels` 中以空格分隔,配置多个分组标签;支持配置多个 `GroupLabels`。 + +- 支持以通配符 \* 的形式,在多个 Host 节点配置分组标签,`tssh` 会将所有的标签汇总起来。 + + ``` + # 以下 testAA 具有标签 group1 group2 label3 label4 group5,可以加上 `#!!` 前缀,以兼容标准 ssh + Host test* + #!! GroupLabels group1 group2 + #!! GroupLabels label3 + Host testAA + #!! GroupLabels label4 group5 + ``` + +## 自动交互 + +- 支持类似 `expect` 的自动交互功能,可以在登录服务器之后,自动匹配服务器的输出,然后自动输入。 + + ``` + Host auto + #!! ExpectCount 5 # 配置自动交互的次数,默认是 0 即无自动交互 + #!! ExpectTimeout 30 # 配置自动交互的超时时间(单位:秒),默认是 30 秒 + #!! ExpectPattern1 *assword # 配置第一个自动交互的匹配表达式 + # 配置第一个自动输入(密文),这是由 tssh --enc-secret 编码得到的字符串,tssh 会自动发送 \r 回车 + #!! ExpectSendPass1 d7983b4a8ac204bd073ed04741913befd4fbf813ad405d7404cb7d779536f8b87e71106d7780b2 + #!! ExpectPattern2 hostname*$ # 配置第二个自动交互的匹配表达式 + #!! ExpectSendText2 echo tssh expect\r # 配置第二个自动输入(明文),需要指定 \r 才会发送回车 + # 以上 ExpectSendPass? 和 ExpectSendText? 只要二选一即可,若都配置则 ExpectSendPass? 的优先级更高 + # -------------------------------------------------- + # 在每个 ExpectPattern 匹配之前,可以配置一个或多个可选的匹配,用法如下: + #!! ExpectPattern3 hostname*$ # 配置第三个自动交互的匹配表达式 + #!! ExpectSendText3 ssh xxx\r # 配置第三个自动输入,也可以换成 ExpectSendPass3 然后配置密文 + #!! ExpectCaseSendText3 yes/no y\r # 在 ExpectPattern3 匹配之前,若遇到 yes/no 则发送 y 并回车 + #!! ExpectCaseSendText3 y/n yes\r # 在 ExpectPattern3 匹配之前,若遇到 y/n 则发送 yes 并回车 + #!! ExpectCaseSendPass3 token d7... # 在 ExpectPattern3 匹配之前,若遇到 token 则解码 d7... 并发送 + # -------------------------------------------------- + #!! ExpectPattern4 token: # 配置第四个自动交互的匹配表达式(这里以动态密码举例) + #!! ExpectSendOtp4 oathtool --totp -b xxxxx # 配置获取动态密码的命令(明文) + #!! ExpectPattern5 token: # 配置第五个自动交互的匹配表达式(这里以动态密码举例) + # 下面是运行 tssh --enc-secret 输入命令 oathtool --totp -b xxxxx 得到的密文串 + #!! ExpectSendEncOtp5 77b4ce85d087b39909e563efb165659b22b9ea700a537f1258bdf56ce6fdd6ea70bc7591ea5c01918537a65433133bc0bd5ed3e4 + ``` + + - 配置 `ExpectCount` 大于 `0` 之后,使用 `tssh --debug` 登录,可以看到 `expect` 捕获到的输出。 + +## 记住密码 + +- 为了兼容标准 ssh ,密码可以单独配置在 `~/.ssh/password` 中,也可以在 `~/.ssh/config` 中加上 `#!!` 前缀。 + +- 推荐使用前面公钥认证的方式,密码的安全性弱一些。如果必须要用密码,建议至少设置好权限,如: + + ```sh + chmod 700 ~/.ssh && chmod 600 ~/.ssh/password ~/.ssh/config + ``` + +- 下面配置 `test1` 和 `test2` 的密码是 `123456`,其他以 `test` 开头的密码是 `111111`: + + ``` + # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh + Host test1 + # 下面是运行 tssh --enc-secret 输入密码 123456 得到的密文串,每次运行结果不同。 + #!! encPassword 756b17766f45bdc44c37f811db9990b0880318d5f00f6531b15e068ef1fde2666550 + + # 如果配置在 ~/.ssh/password 中,则不需要考虑是否兼容标准 ssh + Host test2 + # 下面是运行 tssh --enc-secret 输入密码 123456 得到的密文串,每次运行结果不同。 + encPassword 051a2f0fdc7d0d40794b845967df4c2d05b5eb0f25339021dc4e02a9d7620070654b + + # ~/.ssh/config 和 ~/.ssh/password 是支持通配符的,tssh 会使用第一个匹配到的值。 + # 这里希望 test2 使用区别于其他 test* 的密码,所以将 test* 放在了 test2 的后面。 + + Host test* + Password 111111 # 支持明文密码,但是推荐使用 tssh --enc-secret 简单加密一下。 + ``` + +- 如果启用了 `ControlMaster` 多路复用,或者是在 `Warp` 终端,需要使用前面 `自动交互` 的方式实现记住密码的效果。配置方式请参考前面 `自动交互`,加上 `Ctrl` 前缀即可,如: + + ``` + Host ctrl + #!! CtrlExpectCount 1 # 配置自动交互的次数,一般只要输入一次密码 + #!! CtrlExpectPattern1 *assword # 配置密码提示语的匹配表达式 + #!! CtrlExpectSendPass1 d7983b... # 配置 tssh --enc-secret 编码后的密码 + ``` + +- 支持记住私钥的`Passphrase`( 推荐使用 `ssh-agent` )。支持与 `IdentityFile` 一起配置, 支持使用私钥文件名代替 Host 别名设置通用密钥的 `Passphrase`。举例: + + ``` + # IdentityFile 和 Passphrase 一起配置,可以加上 `#!!` 前缀,以兼容标准 ssh + Host test1 + IdentityFile /path/to/id_rsa + # 下面是运行 tssh --enc-secret 输入密码 123456 得到的密文串,每次运行结果不同。 + #!! encPassphrase 6f419911555b0cdc84549ae791ef69f654118d734bb4351de7e83163726ef46d176a + + # 在 ~/.ssh/config 中配置通用私钥 ~/.ssh/id_ed25519 对应的 Passphrase + # 可以加上通配符 * 以避免 tssh 搜索和选择时,文件名出现在服务器列表中。 + Host id_ed25519* + # 下面是运行 tssh --enc-secret 输入密码 111111 得到的密文串,每次运行结果不同。 + #!! encPassphrase 3a929328f2ab1be0ba3fccf29e8125f8e2dac6dab73c946605cf0bb8060b05f02a68 + + # 在 ~/.ssh/password 中配置则不需要通配符*,也不会出现在服务器列表中。 + Host id_rsa + Passphrase 111111 # 支持明文密码,但是推荐使用 tssh --enc-secret 简单加密一下。 + ``` + +## 记住答案 + +- 除了私钥和密码,还有一种登录方式,英文叫 keyboard interactive ,是服务器返回一些问题,客户端提供正确的答案就能登录,很多自定义的一次性密码就是利用这种方式实现的。 + +- 对于只有一个问题,且答案(密码)固定不变的,只要配置 `QuestionAnswer1` 即可。对于有多个问题的,可以按问题的序号进行配置,也可以按问题的 hex 编码进行配置。 + +- 使用 `tssh --debug` 登录,会输出问题的 hex 编码,从而知道该如何使用 hex 编码进行配置。配置举例: + + ``` + # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh + Host test1 + # 下面是运行 tssh --enc-secret 输入答案 `答案一` 得到的密文串,每次运行结果不同。 + encQuestionAnswer1 482de7690ccc5229299ccadd8de1cb7c6d842665f0dc92ff947a302f644817baecbab38601 + Host test2 + # 下面是运行 tssh --enc-secret 输入答案 `答案一` 得到的密文串,每次运行结果不同。 + encQuestionAnswer1 43e86f1140cf6d8c786248aad95a26f30633f1eab671676b0860ecb5b1a64fb3ec5212dddf + QuestionAnswer2 答案二 # 支持明文答案,但是推荐使用 tssh --enc-secret 简单加密一下。 + QuestionAnswer3 答案三 + Host test3 + # 其中 `6e616d653a20` 是问题 `name: ` 的 hex 编码,`enc` 前缀代表配置的是密文串。 + # 下面是运行 tssh --enc-secret 输入答案 `my_name` 得到的密文串,每次运行结果不同。 + enc6e616d653a20 775f2523ab747384e1661aba7779011cb754b73f2e947672c7fd109607b801d70902d1 + 636f64653a20 my_code # 其中 `636f64653a20` 是问题 `code: ` 的 hex 编码, `my_code` 是明文答案 + ``` + +- 对于可以通过命令行获取到的动态密码,则可以如下配置(同样支持按序号或 hex 编码进行配置): + + ``` + Host otp + OtpCommand1 oathtool --totp -b xxxxx # 按序号配置获取动态密码的命令 + otp636f64653a20 oathtool --totp -b xxxxx # 按 `code: ` 的 hex 编码 `636f64653a20` 配置获取动态密码的命令 + # 下面是运行 tssh --enc-secret 输入命令 oathtool --totp -b xxxxx 得到的密文串,加上 `enc` 前缀进行配置 + encOtpCommand2 77b4ce85d087b39909e563efb165659b22b9ea700a537f1258bdf56ce6fdd6ea70bc7591ea5c01918537a65433133bc0bd5ed3e4 + encotp636f64653a20 77b4ce85d087b39909e563efb165659b22b9ea700a537f1258bdf56ce6fdd6ea70bc7591ea5c01918537a65433133bc0bd5ed3e4 + ``` + +- 如果启用了 `ControlMaster` 多路复用,或者是在 `Warp` 终端,请参考前面 `自动交互` 加 `Ctrl` 前缀来实现。 + + ``` + Host ctrl_otp + #!! CtrlExpectCount 1 # 配置自动交互的次数,一般只要输入一次密码 + #!! CtrlExpectPattern1 token: # 配置密码提示语的匹配表达式(这里以动态密码举例) + #!! CtrlExpectSendOtp1 oathtool --totp -b xxxxx # 配置获取动态密码的命令(明文) + #!! CtrlExpectSendEncOtp1 77b4ce85d0... # 或者配置 tssh --enc-secret 得到的密文串 + ``` + +## 可选配置 + +- 支持在 `~/.tssh.conf`( Windows 是 `C:\Users\your_name\.tssh.conf` )中进行以下自定义配置: + + ``` + # SSH 配置路径,默认为 ~/.ssh/config + ConfigPath = ~/.ssh/config + + # 扩展配置路径,默认为 ~/.ssh/password + ExConfigPath = ~/.ssh/password + + # trz 上传时,对话框打开的路径,为空时打开上次的路径, 默认为空 + DefaultUploadPath = ~/Downloads + + # tsz 下载时,自动保存的路径,为空时弹出对话框手工选择,默认为空 + DefaultDownloadPath = ~/Downloads + + # tssh 搜索和选择服务器时,每页显示的记录数,默认为 10 + PromptPageSize = 10 + + # tssh 搜索和选择服务器时,默认是类似 vim 的 normal 模式,想默认进入搜索模式可如下配置: + PromptDefaultMode = search + + # tssh 搜索和选择服务器时,详情中显示的配置列表,默认如下: + PromptDetailItems = Alias Host Port User GroupLabels IdentityFile ProxyCommand ProxyJump RemoteCommand + + # tssh 搜索和选择服务器时,可以自定义光标和选中的图标: + PromptCursorIcon = 🧨 + PromptSelectedIcon = 🍺 + + # 登录后自动设置终端标题,退出后不会重置,你需要参考下文在本地 shell 中设置 PROMPT_COMMAND + SetTerminalTitle = Yes + ``` + +## 其他功能 + +- 使用 `-f` 后台运行时,可以加上 `--reconnect` 参数,在后台进程因连接断开等而退出时,会自动重新连接。 + +- 使用 `--dragfile` 启用拖拽上传功能,想默认启用则可以在 `~/.ssh/config` 或 `ExConfigPath` 中配置: + + ``` + Host * + # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh + EnableDragFile Yes + ``` + +- 使用 `--zmodem` 启用 `rz / sz` 功能,想默认启用则可以在 `~/.ssh/config` 或 `ExConfigPath` 中配置: + + ``` + Host server0 + # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh + EnableZmodem Yes + ``` + + - 需要在客户端( 本地电脑 )上安装 `lrzsz`,Windows 可以从 [lrzsz-win32](https://github.com/trzsz/lrzsz-win32/releases) 下载解压并加到 `PATH` 中,也可以如下安装: + + ``` + scoop install https://trzsz.github.io/lrzsz.json + + choco install lrzsz --version=0.12.21 + ``` + + - 关于 `rz / sz` 进度条,己传大小和传输速度会有一点偏差,它的主要作用只是指示传输正在进行中。 + +- 使用 `-oEnableTrzsz=No` 禁用 trzsz 功能,想默认禁用则可以在 `~/.ssh/config` 或 `ExConfigPath` 中配置: + + ``` + Host server1 + # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh + EnableTrzsz No + ``` + +- 上文说的“记住密码”和“记住答案”,只要在配置项前面加上 `enc` 则可以配置密文,防止被人窥屏。并且,密文可以解决密码含有`#`的问题。 + + - 运行 `tssh --enc-secret`,输入密码或答案,可得到用于配置的密文( 相同密码每次运行结果不同 ): + + ``` + Host server2 + # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh + encPassword de88c4dbdc95d85303682734e2397c4d8dd29bfff09ec53580f31dd40291fc8c7755 + encQuestionAnswer1 93956f6e7e9f2aef3af7d6a61f7046dddf14aa4bbd9845dbb836fe3782b62ac0d89f + ``` + +- 运行 `tssh --new-host` 可以在 TUI 界面轻松添加 SSH 配置,并且完成后可以立即登录。 + +- 运行 `tssh --install-trzsz` 可以将 [trzsz](https://github.com/trzsz/trzsz-go) ( `trz` / `tsz` ) 安装到服务器上。 + + - 默认安装到 `~/.local/bin/` 目录,可以通过 `--install-path /path/to/install` 指定安装目录。 + - 若 `--install-path` 安装目录含有 `~/`,则必须加上单引号,如`--install-path '~/path'`。 + - 若获取 `trzsz` 的最新版本号失败,可以通过 `--trzsz-version x.x.x` 参数自行指定。 + - 若下载 `trzsz` 的安装包失败,可以自行下载并通过 `--trzsz-bin-path /path/to/trzsz.tar.gz` 参数指定。 + - 注意:`--install-trzsz` 不支持 Windows 服务器,不支持跳板机( 除非以 `ProxyJump` 跳过 )。 + +- 关于修改终端标题,其实无需 `tssh` 就能实现,只要在服务器的 shell 配置文件中(如`~/.bashrc`)配置: + + ```sh + # 设置固定的服务器标题 + PROMPT_COMMAND='echo -ne "\033]0;固定的服务器标题\007"' + + # 根据环境变量动态变化的标题 + PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"' + ``` + + - 如果在 `~/.tssh.conf` 中设置了 `SetTerminalTitle = Yes`,则会在登录后自动设置终端标题,但是服务器上的 `PROMPT_COMMAND` 会覆盖 `tssh` 设置的标题。 + - 在 `tssh` 退出后不会重置为原来的标题,你需要在本地 shell 中设置 `PROMPT_COMMAND`,让它覆盖 `tssh` 设置的标题。 + +## 快捷键 + +| 操作 | 全局快捷键 | 非搜索快捷键 | 快捷键描述 | +| --------- | ------------------------------- | ------------ | --------------- | +| Confirm | Enter | | 确认并登录 | +| Quit/Exit | Ctrl+C Ctrl+Q | q Q | 取消并退出 | +| Move Prev | Ctrl+K Shift+Tab ↑ | k K | 往上移光标 | +| Move Next | Ctrl+J Tab ↓ | j J | 往下移光标 | +| Page Up | Ctrl+H Ctrl+U Ctrl+B PageUp ← | h H u U b B | 往上翻一页 | +| Page Down | Ctrl+L Ctrl+D Ctrl+F PageDown → | l L d D f F | 往下翻一页 | +| Goto Home | Home | g | 跳到第一行 | +| Goto End | End | G | 跳到最尾行 | +| EraseKeys | Ctrl+E | e E | 擦除搜索关键字 | +| TglSearch | / | | 切换搜索功能 | +| Tgl Help | ? | | 切换帮助信息 | +| TglSelect | Ctrl+X Ctrl+Space Alt+Space | Space x X | 切换选中状态 | +| SelectAll | Ctrl+A | a A | 全选当前页 | +| SelectOpp | Ctrl+O | o O | 反选当前页 | +| Open Wins | Ctrl+W | w W | 新窗口批量登录 | +| Open Tabs | Ctrl+T | t T | 新 Tab 批量登录 | +| Open Pane | Ctrl+P | p P | 分屏批量登录 | + +## 故障排除 + +- 在 Warp 终端,分块 Blocks 的功能需要将 `tssh` 重命名为 `ssh`,推荐建个软链接( 对更新友好 ): + + ``` + sudo ln -sv $(which tssh) /usr/local/bin/ssh + ``` + + - 软链后,`ssh -V` 应输出 `trzsz ssh` 加版本号,如果不是,说明软链不成功,或者在 `PATH` 中 `openssh` 的优先级更高,你要软链到另一个地方或者调整 `PATH` 的优先级。 + + - 软链后,要直接使用 `ssh`,它等价于 `tssh`。如果还是用 `tssh` 是不会支持分块 Blocks 功能的。 + + - `--dragfile` 参数可能会让 Warp 分块功能失效,请参考前文配置 `EnableDragFile` 来启用拖拽功能。 + + - 拖拽文件或目录进入 Warp 终端后,可能不会立即触发上传,需要多按一次`回车`键,才会上传。 + +- 如果你在使用 Windows7 或者旧版本的 Windows10 等,遇到 `enable virtual terminal failed` 的错误。 + + - 可以尝试在 [Cygwin](https://www.cygwin.com/)、[MSYS2](https://www.msys2.org/) 或 [Git Bash](https://www.atlassian.com/git/tutorials/git-bash) 内使用 `tssh`。 + +- 如果在 `~/.ssh/config` 中配置了 `tssh` 特有的配置项后,标准 `ssh` 报错 `Bad configuration option`。 + + - 可以在出错配置项中加上前缀 `#!!`,标准 `ssh` 会将它当作注释,而 `tssh` 则会认为它是有效配置之一。 + +## 录屏演示 + +![tssh登录演示](https://trzsz.github.io/images/tssh.gif) + +![tssh批量执行](https://trzsz.github.io/images/batch_ssh.gif) + +## 联系方式 + +有什么问题可以发邮件给作者 ,也可以提 [Issues](https://github.com/trzsz/trzsz-ssh/issues) 。欢迎加入 QQ 群:318578930。 + +## 赞助打赏 + +[❤️ 赞助 trzsz ❤️](https://github.com/trzsz),请作者喝杯咖啡 ☕ ? 谢谢您们的支持! diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..72c1019 --- /dev/null +++ b/README.en.md @@ -0,0 +1,525 @@ +# trzsz-ssh ( tssh ) + +An ssh client that supports [trzsz](https://trzsz.github.io/), supports searching and selecting servers for batch login. + +Website: [https://trzsz.github.io/ssh](https://trzsz.github.io/ssh) ( English )  中文文档:[https://trzsz.github.io/cn/ssh](https://trzsz.github.io/cn/ssh) + +[![MIT License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://choosealicense.com/licenses/mit/) +[![GitHub Release](https://img.shields.io/github/v/release/trzsz/trzsz-ssh)](https://github.com/trzsz/trzsz-ssh/releases) + +## Introduce + +- Does your favorite ssh terminal have server management feature? Does it support remembering password? Does it have a cool file transfer tool? + +- tssh supports selecting or searching servers configured in `~/.ssh/config`, supports vim operation habit, provides a server management solution. + +- tssh supports selecting multiple servers, logging in to them in batches, and executing pre-specified commands in batches. + +- tssh supports configuring server login password, solves the trouble of entering password each time ( It's recommended to use the public key to login ). + +- tssh supports [trzsz](https://trzsz.github.io/) ( trz / tsz ) natively, solved the issue of slow upload speeds while using `trzsz ssh` in Windows. + +- _On the author's MacOS, the upload speed using `trzsz ssh` is about 10 MB/s, while using `tssh` can reach over 80 MB/s._ + +## Installation + +**_Here is how to install `trzsz-ssh (tssh)` on the client side (choose one):_** + +- Install with [scoop](https://scoop.sh/) / [winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/) / [choco](https://community.chocolatey.org/) on Windows + +
scoop install tssh / winget install tssh / choco install tssh + + ```sh + scoop install tssh + ``` + + ```sh + winget install tssh + ``` + + ```sh + choco install tssh + ``` + +
+ +- Install with [homebrew](https://brew.sh/) on MacOS + +
brew install trzsz-ssh + + ```sh + brew update + brew install trzsz-ssh + ``` + +
+ +- Install with apt on Ubuntu + +
sudo apt install tssh + + ```sh + sudo apt update && sudo apt install software-properties-common + sudo add-apt-repository ppa:trzsz/ppa && sudo apt update + + sudo apt install tssh + ``` + +
+ +- Install with apt on Debian + +
sudo apt install tssh + + ```sh + sudo apt install curl gpg + curl -s 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x7074ce75da7cc691c1ae1a7c7e51d1ad956055ca' \ + | gpg --dearmor -o /usr/share/keyrings/trzsz.gpg + echo 'deb [signed-by=/usr/share/keyrings/trzsz.gpg] https://ppa.launchpadcontent.net/trzsz/ppa/ubuntu jammy main' \ + | sudo tee /etc/apt/sources.list.d/trzsz.list + sudo apt update + + sudo apt install tssh + ``` + +
+ +- Install with yum on Linux + +
sudo yum install tssh + + - Install with [gemfury](https://gemfury.com/) repository. + + ```sh + echo '[trzsz] + name=Trzsz Repo + baseurl=https://yum.fury.io/trzsz/ + enabled=1 + gpgcheck=0' | sudo tee /etc/yum.repos.d/trzsz.repo + + sudo yum install tssh + ``` + + - Install with [wlnmp](https://www.wlnmp.com/install) repository. It's not necessary to configure the epel repository for tssh. + + ```sh + curl -fsSL "https://sh.wlnmp.com/wlnmp.sh" | bash + + sudo yum install tssh + ``` + +
+ +- Install with [yay](https://github.com/Jguer/yay) on ArchLinux + +
yay -S tssh + + ```sh + yay -Syu + yay -S tssh + ``` + +
+ +- Install with Go ( Requires go 1.20 or later ) + +
go install github.com/trzsz/trzsz-ssh/cmd/tssh@latest + + ```sh + go install github.com/trzsz/trzsz-ssh/cmd/tssh@latest + ``` + + The binaries are usually located in ~/go/bin/ ( C:\Users\your_name\go\bin\ on Windows ). + +
+ +- Build from source ( Requires go 1.20 or later ) + +
sudo make install + + ```sh + git clone --depth 1 https://github.com/trzsz/trzsz-ssh.git + cd trzsz-ssh + make + sudo make install + ``` + +
+ +- Download from the [Releases](https://github.com/trzsz/trzsz-ssh/releases) + +**_[trzsz](https://trzsz.github.io/) needs to be installed on the server to use `trz / tsz` for uploading and downloading files._** + +_Choose either the [Go version](https://trzsz.github.io/go) ( ⭐ Recommended ), [Py version](https://trzsz.github.io/), or [Js version](https://trzsz.github.io/js)._ + +_If trzsz is not installed on the server, you can still use `tssh`, but can't use `trz / tsz` for uploading and downloading._ + +## How to use + +_`~/` represents the HOME directory. Please replace `~/` below with `C:\Users\your_name\` on Windows._ + +- Generate a key pair on the client, generally stored in `~/.ssh/` ( choose one of the following ): + + - `ssh-keygen -t ed25519` generates a ED25519 key pair, private key `~/.ssh/id_ed25519`, public key `~/.ssh/id_ed25519.pub`. + - `ssh-keygen -t rsa -b 4096` generates a RSA key pair, private key `~/.ssh/id_rsa`, public key `~/.ssh/id_rsa.pub`. + +- Append the public key to the `~/.ssh/authorized_keys` file on the server, and set the correct permissions: + + ```sh + chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys + ``` + +- Configure the `~/.ssh/config` file on the client, for example: + + ``` + Host alias1 + HostName 192.168.0.1 + Port 22 + User your_name + Host alias2 + HostName 192.168.0.2 + Port 22 + User your_name + ``` + +- Use `tssh` command to log in to the server, `tssh alias1` command to log in to the server corresponding to `alias1` in `~/.ssh/config`. + +- Execute the `tssh` command without arguments, you can select or search the configured servers in `~/.ssh/config` to log in. + +## Batch Login + +- tssh supports selecting multiple servers in `iTerm2`( Requires [Python API](https://iterm2.com/python-api-auth.html), no need to `Allow all apps to connect` ),`tmux` and `Windows Terminal`, logging in to them in batches, and executing pre-specified commands in batches. + +- Press `Space`, `Ctrl+X` to toggle select the current server. If it cannot be selected, it means that the current terminal is not supported yet. Please run `tmux` first. + +- Press `Ctrl+P` will split panes for batch login, `Ctrl+W` will open new windows for batch login, and `Ctrl+T` will open new tabs for batch login. + +- Execute the `tssh` command without arguments, you can log in to servers in batches. And you can specify the commands to be executed in batches by `-o RemoteCommand`. And you can switch to an interactive shell after executing the specified command. `Windows Terminal` does not support semicolon `;`, you can use `|cat&&` instead. For example: + + ```sh + tssh -t -o RemoteCommand='ping -c3 trzsz.github.io ; bash' + tssh -t -o RemoteCommand="ping -c3 trzsz.github.io |cat&& bash" + ``` + +## Group Labels + +- If there are a lot of servers, `GroupLabels` can be used to quickly find the target server when searching by `/`. + +- After press `/` and search for a group label, press `Enter` to lock it. You can search for another group label by pressing `/` again, and press `Enter` to lock it too. + +- In non-search mode, press `E` to erase the current search group labels. In search mode, press `Ctrl + E` to have the same effect. + +- Supports configuring multiple group labels separated by spaces in one `GroupLabels`. Supports configuring multiple `GroupLabels`. + +- Supports configuring group labels on multiple Host nodes in the form of wildcard \*, and `tssh` will summarize all the group labels. + + ``` + # The following testAA has group labels group1 group2 label3 label4 group5. Add `#!!` prefix to be compatible with openssh. + Host test* + #!! GroupLabels group1 group2 + #!! GroupLabels label3 + Host testAA + #!! GroupLabels label4 group5 + ``` + +## Automated Interaction + +- Supports automated interaction feature similar to `expect`. After logging into the server, it automatically matches the server's output and then enters input accordingly. + + ``` + Host auto + #!! ExpectCount 5 # Configures the number of automated interactions, default is 0 which means no automated interaction + #!! ExpectTimeout 30 # Configures the timeout for automated interaction (in seconds), default is 30 seconds + #!! ExpectPattern1 *assword # Configures the first automated interaction match expression + # Configures the first automated input (encrypted). It was encoded by `tssh --enc-secret`, `tssh` will send \r (enter) automatically + #!! ExpectSendPass1 d7983b4a8ac204bd073ed04741913befd4fbf813ad405d7404cb7d779536f8b87e71106d7780b2 + #!! ExpectPattern2 hostname*$ # Configures the second automated interaction match expression + #!! ExpectSendText2 echo tssh expect\r # Configures the second automated input (plaintext), specify \r to send enter + # Choose either ExpectSendPass? or ExpectSendText? for each interaction; if both are configured, ExpectSendPass? has higher priority + # -------------------------------------------------- + # Before each ExpectPattern match, one or multiple optional matches can be configured as follows: + #!! ExpectPattern3 hostname*$ # Configures the third automated interaction match expression + #!! ExpectSendText3 ssh xxx\r # Configures the third automated input, can also use ExpectSendPass3 then configure with encrypted text + #!! ExpectCaseSendText3 yes/no y\r # Before matching ExpectPattern3, if encountering yes/no, then send y and enter + #!! ExpectCaseSendText3 y/n yes\r # Before matching ExpectPattern3, if encountering y/n, then send yes and enter + #!! ExpectCaseSendPass3 token d7... # Before matching ExpectPattern3, if encountering token, then decode d7... and send + # -------------------------------------------------- + #!! ExpectPattern4 token: # Configures the fourth automated interaction match expression (one-time password) + #!! ExpectSendOtp4 oathtool --totp -b xxxxx # Configure the command line to obtain the one-time password + #!! ExpectPattern5 token: # Configures the fifth automated interaction match expression (one-time password) + # The following ciphertext was generated by encoding `oathtool --totp -b xxxxx` with `tssh --enc-secret`. + #!! ExpectSendEncOtp5 77b4ce85d087b39909e563efb165659b22b9ea700a537f1258bdf56ce6fdd6ea70bc7591ea5c01918537a65433133bc0bd5ed3e4 + ``` + + - Login using `tssh --debug` if `ExpectCount` is greater than `0`, you can see the output captured by `expect`. + +## Remember Password + +- In order to be compatible with openssh, the password can be configured separately in `~/.ssh/password`, or you can add `#!!` prefix in `~/.ssh/config`. + +- It's recommended to use the public key authentication. If you have to use the password authentication, it's recommended to set the permissions: + + ```sh + chmod 700 ~/.ssh && chmod 600 ~/.ssh/password ~/.ssh/config + ``` + +- The passwords configured below for `test1` and `test2` are `123456`, and the passwords for other aliases starting with `test` are `111111`: + + ``` + # If configured in ~/.ssh/config, you can add `#!!` prefix to be compatible with openssh. + Host test1 + # The following ciphertext was generated by encoding `123456` with `tssh --enc-secret`. + #!! encPassword 756b17766f45bdc44c37f811db9990b0880318d5f00f6531b15e068ef1fde2666550 + + # If configured in ~/.ssh/password, there is no need to consider whether it's compatible with openssh. + Host test2 + # The following ciphertext was generated by encoding `123456` with `tssh --enc-secret`. + encPassword 051a2f0fdc7d0d40794b845967df4c2d05b5eb0f25339021dc4e02a9d7620070654b + + # ~/.ssh/config and ~/.ssh/password support wildcards, and tssh will use the first matched value. + # Here we want test2 to use a different password from other test*, so we put test* behind test2. + + Host test* + Password 111111 # supports plain text, but it is recommended to encrypt with `tssh --enc-secret`. + ``` + +- - If `ControlMaster` multiplexing is enabled or using `Warp` terminal, you will need to use the `Automated Interaction` mentioned earlier to achieve remembering password. Please refer to the earlier `Automated Interaction` section, simply add a `Ctrl` prefix as follows: + + ``` + Host ctrl + #!! CtrlExpectCount 1 # Configure the number of automated interactions, typically only requires entering the password once + #!! CtrlExpectPattern1 *assword # Configure the matching expression for the password prompt + #!! CtrlExpectSendPass1 d7983b... # Configure the password encoded by `tssh --enc-secret` + ``` + +- Support remember `Passphrase` for private keys ( It's recommended to use `ssh-agent` ). Support configuring `Passphrase` together with `IdentityFile`. Support configuring `Passphrase` using private key filename instead of host alias. For example: + + ``` + # Configuring Passphrase together with IdentityFile. Add `#!!` prefix to be compatible with openssh. + Host test1 + IdentityFile /path/to/id_rsa + # The following ciphertext was generated by encoding `123456` with `tssh --enc-secret`. + #!! encPassphrase 6f419911555b0cdc84549ae791ef69f654118d734bb4351de7e83163726ef46d176a + + # Configure the Passphrase corresponding to the private key ~/.ssh/id_ed25519 in ~/.ssh/config + # The wildcard * can be added to prevent the filename from appearing in the tssh server list. + Host id_ed25519* + # The following ciphertext was generated by encoding `111111` with `tssh --enc-secret`. + #!! encPassphrase 3a929328f2ab1be0ba3fccf29e8125f8e2dac6dab73c946605cf0bb8060b05f02a68 + + # If configured in ~/.ssh/password, the wildcard * is not required and will not appear in the server list. + Host id_rsa + Passphrase 111111 # supports plain text, but it is recommended to encrypt with `tssh --enc-secret`. + ``` + +## Remember Answers + +- In addition, there is a keyboard interactive authentication. The server returns some questions, and log in by providing the correct answers. Many custom one-time passwords are implemented by it. + +- For those with one question and a fixed answer, just configure `QuestionAnswer1`. For those with multiple questions, the answer to each question can be configured by serial number, or by the hex code of the question. + +- Login with `tssh --debug`, the hex code of the questions will be output, so that you will know how to configure with the hex code. For example: + + ``` + # If configured in ~/.ssh/config, add `#!!` prefix to be compatible with openssh. + Host test1 + # The following ciphertext was generated by encoding `TheAnswer1` with `tssh --enc-secret`. + encQuestionAnswer1 4f6b79d0e4e48fc56ee29c61bd19559a322cd07f7d27f2a7f33978671be1b522d549252b22ee + Host test2 + # The following ciphertext was generated by encoding `TheAnswer1` with `tssh --enc-secret`. + encQuestionAnswer1 09d6936c104f7bbd62e3b4dc43d746496a368776b85d37b1ce8cecc2ace1b920af0ca5a1812b + QuestionAnswer2 TheAnswer2 # supports plain text, but it is recommended to encrypt with `tssh --enc-secret`. + QuestionAnswer3 TheAnswer3 + Host test3 + # The `6e616d653a20` is the hex code of `name: `, the `enc` prefix indicates that it's ciphertext. + # The following ciphertext was generated by encoding `my_name` with `tssh --enc-secret`. + enc6e616d653a20 775f2523ab747384e1661aba7779011cb754b73f2e947672c7fd109607b801d70902d1 + 636f64653a20 my_code # The `636f64653a20` is the hex code of `code: `, `my_code` is plain answer. + ``` + +- For one-time password that can be obtained by the command line, you can configure them as follows (configure by serial number or hex code of the question): + + ``` + Host otp + OtpCommand1 oathtool --totp -b xxxxx # Configure the command line to obtain the one-time password by serial number + otp636f64653a20 oathtool --totp -b xxxxx # Configure the command line by the hex code of the question `code: ` that is `636f64653a20` + # The following ciphertext was generated by encoding `oathtool --totp -b xxxxx` with `tssh --enc-secret`. Add the `enc` prefix for configuration. + encOtpCommand2 77b4ce85d087b39909e563efb165659b22b9ea700a537f1258bdf56ce6fdd6ea70bc7591ea5c01918537a65433133bc0bd5ed3e4 + encotp636f64653a20 77b4ce85d087b39909e563efb165659b22b9ea700a537f1258bdf56ce6fdd6ea70bc7591ea5c01918537a65433133bc0bd5ed3e4 + ``` + +- If `ControlMaster` multiplexing is enabled or using `Warp` terminal, you will need to use the `Automated Interaction` mentioned earlier to achieve remembering answers. + + ``` + Host ctrl_otp + #!! CtrlExpectCount 1 # Configure the number of automated interactions, typically only requires entering the password once + #!! CtrlExpectPattern1 token: # Configure the matching expression for the password prompt (one-time password) + #!! CtrlExpectSendOtp1 oathtool --totp -b xxxxx # Configure the command line to obtain the one-time password + #!! CtrlExpectSendEncOtp1 77b4ce85d0... # Or configure the encrypted command line encoded using `tssh --enc-secret` + ``` + +## Configuration + +- The following custom configurations are supported in `~/.tssh.conf` (`C:\Users\your_name\.tssh.conf` on Windows): + + ``` + # SSH configuration path, the default is ~/.ssh/config + ConfigPath = ~/.ssh/config + + # Extended configuration path, the default is ~/.ssh/password + ExConfigPath = ~/.ssh/password + + # The default path of the file dialog for trz uploading, the default is empty which opening the last path. + DefaultUploadPath = ~/Downloads + + # The automatically save path for tsz downloading, the default is empty which poping up a folder dialog. + DefaultDownloadPath = ~/Downloads + + # When searching and selecting servers with tssh, the number of records displayed on each page, the default is 10. + PromptPageSize = 10 + + # When searching and selecting servers with tssh, default is normal mode similar to vim. Configure to search mode as follows: + PromptDefaultMode = search + + # When searching and selecting servers with tssh, the items displayed in details. The default is as follows: + PromptDetailItems = Alias Host Port User GroupLabels IdentityFile ProxyCommand ProxyJump RemoteCommand + + # When searching and selecting servers with tssh, you can customize the cursor and selected icon: + PromptCursorIcon = 🧨 + PromptSelectedIcon = 🍺 + + # Auto set terminal title after login. It will not be reset after exiting. Please set PROMPT_COMMAND in local shell. + SetTerminalTitle = Yes + ``` + +## Other Features + +- Use `-f` to run in the background, you can add `--reconnect`, it will automatically reconnect when the background process exits. + +- Use `--dragfile` to enable the drag and drop to upload feature. If you want to enable it by default, you can configure it in `~/.ssh/config` or in the extended configuration `ExConfigPath`: + + ``` + Host * + # If configured in ~/.ssh/config, add `#!!` prefix to be compatible with openssh. + EnableDragFile Yes + ``` + +- Use `--zmodem` to enable the `rz / sz` feature. If you want to enable it by default, you can configure it in `~/.ssh/config` or in the extended configuration `ExConfigPath`: + + ``` + Host server0 + # If configured in ~/.ssh/config, add `#!!` prefix to be compatible with openssh. + EnableZmodem Yes + ``` + + - `lrzsz` needs to be installed on the client ( local computer ). For Windows, you can download and unzip it from [lrzsz-win32](https://github.com/trzsz/lrzsz-win32/releases) and add it to `PATH`, or install it as follows: + + ``` + scoop install https://trzsz.github.io/lrzsz.json + + choco install lrzsz --version=0.12.21 + ``` + + - About the progress, the transferred and speed are not precise. It just indicating that the transfer is in progress. + +- Use `-oEnableTrzsz=No` to disable the trzsz feature. If you want to disable it by default, you can configure it in `~/.ssh/config` or in the extended configuration `ExConfigPath`: + + ``` + Host server1 + # If configured in ~/.ssh/config, add `#!!` prefix to be compatible with openssh. + EnableTrzsz No + ``` + +- For the "remember password" and "remember answer" mentioned above, add `enc` in front of the configuration item, you can configure the ciphertext to prevent people from snooping on the screen. Cipher text can solve the issue of passwords containing `#` too. + + Run `tssh --enc-secret`, enter the plaintext of the password or answer, and you can get the ciphertext used for configuration (the same password will have different encryption results each time): + + ``` + Host server2 + # If configured in ~/.ssh/config, add `#!!` prefix to be compatible with openssh. + encPassword de88c4dbdc95d85303682734e2397c4d8dd29bfff09ec53580f31dd40291fc8c7755 + encQuestionAnswer1 93956f6e7e9f2aef3af7d6a61f7046dddf14aa4bbd9845dbb836fe3782b62ac0d89f + ``` + +- Run `tssh --new-host` to easily add SSH configuration in the TUI interface, and you can log in immediately after completion. + +- Run `tssh --install-trzsz` to install [trzsz](https://github.com/trzsz/trzsz-go) to the server automatically. + + - It is installed to the `~/.local/bin/` directory by default. You can specify the installation directory through `--install-path /path/to/install`. + - If the `--install-path` installation directory contains `~/`, single quotes must be added, such as `--install-path '~/path'`. + - If obtaining the latest version of `trzsz` fails, you can specify it through `--trzsz-version x.x.x`. + - If downloading the `trzsz` installation package fails, you can download and specify it through `--trzsz-bin-path /path/to/trzsz.tar.gz`. + - Note: `--install-trzsz` does not support Windows server, and does not support jump server (unless using `ProxyJump`). + +- About changing the terminal title, it can be achieved without `tssh`. It only needs to be configured in the server's shell configuration file (such as `~/.bashrc`): + + ```sh + # Set fixed server title + PROMPT_COMMAND='echo -ne "\033]0;Fixed server title\007"' + + # Dynamically changing title based on environment variables + PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"' + ``` + + - If `SetTerminalTitle = Yes` is set in `~/.tssh.conf`, the terminal title is automatically set after login, but `PROMPT_COMMAND` on the server overrides the title set by `tssh`. + - `tssh` does not reset to the original title after exiting, you need to set `PROMPT_COMMAND` in the local shell so that it overrides the title set by `tssh`. + +## Shortcuts + +| Action | Global shortcuts | Non search shortcuts | Shortcuts description | +| --------- | ------------------------------- | -------------------- | -------------------------- | +| Confirm | Enter | | Confirm and login | +| Quit/Exit | Ctrl+C Ctrl+Q | q Q | Cancel and quit | +| Move Prev | Ctrl+K Shift+Tab ↑ | k K | Move cursor up | +| Move Next | Ctrl+J Tab ↓ | j J | Move cursor down | +| Page Up | Ctrl+H Ctrl+U Ctrl+B PageUp ← | h H u U b B | Page up | +| Page Down | Ctrl+L Ctrl+D Ctrl+F PageDown → | l L d D f F | Page down | +| Goto Home | Home | g | Go to the first item | +| Goto End | End | G | Go to the last item | +| EraseKeys | Ctrl+E | e E | Erase search keywords | +| TglSearch | / | | Toggle search function | +| Tgl Help | ? | | Toggle help information | +| TglSelect | Ctrl+X Ctrl+Space Alt+Space | Space x X | Toggle selection | +| SelectAll | Ctrl+A | a A | Select all current items | +| SelectOpp | Ctrl+O | o O | Select the opposite items | +| Open Wins | Ctrl+W | w W | Batch login in new windows | +| Open Tabs | Ctrl+T | t T | Batch login in new tabs | +| Open Pane | Ctrl+P | p P | Batch login in new panes | + +## Trouble shooting + +- In the Warp terminal, the features like Blocks requires renaming `tssh` to `ssh`. It is recommended to create a soft link (friendly for updates): + + ``` + sudo ln -sv $(which tssh) /usr/local/bin/ssh + ``` + + - After the soft link, `ssh -V` should output `trzsz ssh` plus the version number. If not, it means that the soft link is unsuccessful, or `openssh` has a higher priority in `PATH`, and you need to soft link to another path or adjust the priority of `PATH`. + + - After the soft link, you need to use `ssh` directly, which is equivalent to `tssh`. If you still use `tssh`, it will not support the Blocks feature. + + - The `--dragfile` argument may disable the Warp features, please refer to the previous section to configure `EnableDragFile` to enable the drag and drop to upload feature. + + - After dragging files and directories into the Warp terminal, the upload may not be triggered immediately. You need to press the `Enter` key once to make it upload. + +- If you are using Windows7 or an older version of Windows10, and getting an error `enable virtual terminal failed`. + + - Try using `tssh` in [Cygwin](https://www.cygwin.com/), [MSYS2](https://www.msys2.org/) or [Git Bash](https://www.atlassian.com/git/tutorials/git-bash). + +- If the `tssh` specific configuration items are configured in `~/.ssh/config`, and openssh report an error `Bad configuration option`. + + - You can add `#!!` prefix to the items, openssh will treat it as a comment, while `tssh` will treat it as one of the valid configurations. + +## Screenshot + +![tssh login demo](https://trzsz.github.io/images/tssh.gif) + +![tssh batch login](https://trzsz.github.io/images/batch_ssh.gif) + +## Contact + +Feel free to email the author , or create an [issue](https://github.com/trzsz/trzsz-ssh/issues). Welcome to join the QQ group: 318578930. + +## Sponsor + +[❤️ Sponsor trzsz ❤️](https://github.com/trzsz), buy the author a drink 🍺 ? Thank you for your support! diff --git a/README.md b/README.md index d66477f..5ce1c9a 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,47 @@ -# trzsz-ssh ( tssh ) - -支持 [trzsz](https://trzsz.github.io/cn/) ( trz / tsz ) 的 ssh 客户端,支持搜索和选择服务器进行批量登录,支持记住密码。 - -An ssh client that supports [trzsz](https://trzsz.github.io/), supports searching and selecting servers for batch login. - -Website: [https://trzsz.github.io/ssh](https://trzsz.github.io/ssh) ( English )  中文文档:[https://trzsz.github.io/cn/ssh](https://trzsz.github.io/cn/ssh) +# trzsz-ssh ( tssh ) - an openssh client alternative [![MIT License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://choosealicense.com/licenses/mit/) [![GitHub Release](https://img.shields.io/github/v/release/trzsz/trzsz-ssh)](https://github.com/trzsz/trzsz-ssh/releases) -## tssh 简介 +## Introduction -- 你喜欢的 ssh 终端是否有好用的服务器管理功能?是否支持记住密码?是否有好用的文件传输工具? +trzsz-ssh ( tssh ) is an open-source project written in golang, designed as a drop-in replacement for the openssh client. It aims to provide complete compatibility with openssh, mirroring all its features, while also offering additional useful features not found in the openssh client. -- tssh 支持选择或搜索 `~/.ssh/config` 中配置的服务器,支持 vim 操作习惯,解决 ssh 终端的服务器管理问题。 +## Basic Features -- tssh 支持一次选择多台服务器,批量登录,并支持批量执行预先指定的命令,方便快速完成批量服务器操作。 +trzsz-ssh ( tssh ) works exactly like the openssh client. The following common features have been implemented: -- tssh 支持配置服务器登录密码,解决每次手工输入密码的麻烦( 自己能控制的服务器,推荐使用公钥登录 )。 +| Features | Support Options | +| :------------: | :----------------------------------------------------------------------------------------------------------------: | +| SSH Proxy | `-J` `-W` `ProxyJump` `ProxyCommand` | +| Pseudo TTY | `-t` `-T` `RequestTTY`, `RemoteCommand` | +| Multiplexing | `ControlMaster` `ControlPath` `ControlPersist` | +| SSH Agent | `-a` `-A` `ForwardAgent` `IdentityAgent` `SSH_AUTH_SOCK` | +| Known Hosts | `UserKnownHostsFile` `GlobalKnownHostsFile` `StrictHostKeyChecking` | +| Authentication | `PubkeyAuthentication` `PasswordAuthentication` `KbdInteractiveAuthentication` | +| Basic Login | `-l` `-p` `-i` `-F` `HostName` `Port` `User` `IdentityFile` `SendEnv` `SetEnv` | +| Port Forward | `-g` `-f` `-N` `-L` `-R` `-D` `LocalForward` `RemoteForward` `DynamicForward` `GatewayPorts` `ClearAllForwardings` | -- tssh 内置支持 [trzsz](https://trzsz.github.io/cn/) ( trz / tsz ) 文件传输工具,一并解决了 Windows 中使用 `trzsz ssh` 上传速度很慢的问题。 +## Extra Features -- _在作者的 MacOS 上,使用 `trzsz ssh` 的上传速度在 10 MB/s 左右,而使用 `tssh` 可以到 80 MB/s 以上。_ +trzsz-ssh ( tssh ) offers additional useful features: -## 安装方法 +| English | 中文 | +| :---------------------------------------------------------: | :-----------------------------------------------------------: | +| [trzsz ( trz / tsz )](https://trzsz.github.io/) | [trzsz ( trz / tsz )](https://trzsz.github.io/cn/) | +| [Login Prompt](README.en.md#how-to-use) | [界面登录](README.cn.md#%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95) | +| [Batch Login](README.en.md#batch-login) | [批量登录](README.cn.md#%E6%89%B9%E9%87%8F%E7%99%BB%E5%BD%95) | +| [Group Labels](README.en.md#group-labels) | [分组标签](README.cn.md#%E5%88%86%E7%BB%84%E6%A0%87%E7%AD%BE) | +| [Automated Interaction](README.en.md#automated-interaction) | [自动交互](README.cn.md#%E8%87%AA%E5%8A%A8%E4%BA%A4%E4%BA%92) | +| [Remember Password](README.en.md#remember-password) | [记住密码](README.cn.md#%E8%AE%B0%E4%BD%8F%E5%AF%86%E7%A0%81) | +| [Personal Configuration](README.en.md#configuration) | [个性配置](README.cn.md#%E5%8F%AF%E9%80%89%E9%85%8D%E7%BD%AE) | +| [Other Features](README.en.md#other-features) | [其他功能](README.cn.md#%E5%85%B6%E4%BB%96%E5%8A%9F%E8%83%BD) | +| [Prompt Shortcuts](README.en.md#shortcuts) | [界面快捷键](README.cn.md#%E5%BF%AB%E6%8D%B7%E9%94%AE) | +| [Trouble Shooting](README.en.md#trouble-shooting) | [故障排除](README.cn.md#%E6%95%85%E9%9A%9C%E6%8E%92%E9%99%A4) | -**_客户端安装 `trzsz-ssh ( tssh )` 的方法如下( 任选其一 ):_** +## Installation -- Windows 可用 [scoop](https://scoop.sh/) / [winget](https://learn.microsoft.com/zh-cn/windows/package-manager/winget/) / [choco](https://community.chocolatey.org/) 安装 +- Install with [scoop](https://scoop.sh/) / [winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/) / [choco](https://community.chocolatey.org/) on Windows
scoop install tssh / winget install tssh / choco install tssh @@ -45,7 +59,7 @@ Website: [https://trzsz.github.io/ssh](https://trzsz.github.io/ssh) ( English )
-- MacOS 可用 [homebrew](https://brew.sh/) 安装 +- Install with [homebrew](https://brew.sh/) on MacOS
brew install trzsz-ssh @@ -56,7 +70,7 @@ Website: [https://trzsz.github.io/ssh](https://trzsz.github.io/ssh) ( English )
-- Ubuntu 可用 apt 安装 +- Install with apt on Ubuntu
sudo apt install tssh @@ -69,7 +83,7 @@ Website: [https://trzsz.github.io/ssh](https://trzsz.github.io/ssh) ( English )
-- Debian 可用 apt 安装 +- Install with apt on Debian
sudo apt install tssh @@ -86,33 +100,33 @@ Website: [https://trzsz.github.io/ssh](https://trzsz.github.io/ssh) ( English )
-- Linux 可用 yum 安装 +- Install with yum on Linux
sudo yum install tssh - - 国内推荐使用 [wlnmp](https://www.wlnmp.com/install) 源,安装 tssh 只需要添加 wlnmp 源( 配置 epel 源不是必须的 ): + - Install with [gemfury](https://gemfury.com/) repository. ```sh - curl -fsSL "https://sh.wlnmp.com/wlnmp.sh" | bash + echo '[trzsz] + name=Trzsz Repo + baseurl=https://yum.fury.io/trzsz/ + enabled=1 + gpgcheck=0' | sudo tee /etc/yum.repos.d/trzsz.repo sudo yum install tssh ``` - - 也可使用 [gemfury](https://gemfury.com/) 源( 只要网络通,所有操作系统通用 ) + - Install with [wlnmp](https://www.wlnmp.com/install) repository. It's not necessary to configure the epel repository for tssh. ```sh - echo '[trzsz] - name=Trzsz Repo - baseurl=https://yum.fury.io/trzsz/ - enabled=1 - gpgcheck=0' | sudo tee /etc/yum.repos.d/trzsz.repo + curl -fsSL "https://sh.wlnmp.com/wlnmp.sh" | bash sudo yum install tssh ```
-- ArchLinux 可用 [yay](https://github.com/Jguer/yay) 安装 +- Install with [yay](https://github.com/Jguer/yay) on ArchLinux
yay -S tssh @@ -123,7 +137,7 @@ Website: [https://trzsz.github.io/ssh](https://trzsz.github.io/ssh) ( English )
-- 用 Go 直接安装( 要求 go 1.20 以上 ) +- Install with Go ( Requires go 1.20 or later )
go install github.com/trzsz/trzsz-ssh/cmd/tssh@latest @@ -131,16 +145,16 @@ Website: [https://trzsz.github.io/ssh](https://trzsz.github.io/ssh) ( English ) go install github.com/trzsz/trzsz-ssh/cmd/tssh@latest ``` - 安装后,`tssh` 程序一般位于 `~/go/bin/` 目录下( Windows 一般在 `C:\Users\your_name\go\bin\` )。 + The binaries are usually located in ~/go/bin/ ( C:\Users\your_name\go\bin\ on Windows ).
-- 可从 [Releases](https://github.com/trzsz/trzsz-ssh/releases) 中直接下载适用的版本 +- Build from source ( Requires go 1.20 or later ) -
或者用 Go 编译( 要求 go 1.20 以上 ) +
sudo make install ```sh - git clone https://github.com/trzsz/trzsz-ssh.git + git clone --depth 1 https://github.com/trzsz/trzsz-ssh.git cd trzsz-ssh make sudo make install @@ -148,379 +162,30 @@ Website: [https://trzsz.github.io/ssh](https://trzsz.github.io/ssh) ( English )
-**_服务器上要安装 [trzsz](https://trzsz.github.io/cn/) 才能使用 `trz / tsz` 上传和下载,可任选其一安装: -[Go 版](https://trzsz.github.io/cn/go)( ⭐ 推荐 )、[Py 版](https://trzsz.github.io/cn/)、[Js 版](https://trzsz.github.io/cn/js)。_** - -_如果服务器不安装 [trzsz](https://trzsz.github.io/cn/),也能用 `tssh`,只是不使用 `trz / tsz` 上传和下载而已。_ - -## 使用方法 - -_`~/` 代表 HOME 目录。在 Windows 中,请将下文的 `~/` 替换成 `C:\Users\your_name\`。_ - -- 在客户端生成密钥对,一般存放在 `~/.ssh/` 下( 只要一种就可以了 ): - - - `ssh-keygen -t ed25519` 生成 ED25519 的,私钥 `~/.ssh/id_ed25519`,公钥 `~/.ssh/id_ed25519.pub`。 - - `ssh-keygen -t rsa -b 4096` 生成 RSA 的,私钥 `~/.ssh/id_rsa`,公钥 `~/.ssh/id_rsa.pub`。 - -- 登录服务器,将公钥( 即前面生成密钥对时 `.pub` 后缀的文件内容 )追加写入服务器上的 `~/.ssh/authorized_keys` 文件中。 - - - 一行代表一个客户端的公钥,注意 `~/.ssh/authorized_keys` 要设置正确的权限: - - ```sh - chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys - ``` - -- 在客户端配置好 `~/.ssh/config` 文件,举例: - - ``` - Host alias1 - HostName 192.168.0.1 - Port 22 - User your_name - Host alias2 - HostName 192.168.0.2 - Port 22 - User your_name - ``` - -- 使用 `tssh` 命令登录服务器,`tssh alias1` 命令登录在 `~/.ssh/config` 中 `alias1` 对应的服务器。 - -- 直接执行 `tssh` 命令( 不带参数 ),可以选择( 搜索 ) `~/.ssh/config` 中配置好的服务器并登录。 - -## 批量登录 - -- 支持在 `iTerm2`( 要开启 [Python API](https://iterm2.com/python-api-auth.html),但不需要`Allow all apps to connect` ),`tmux` 和 `Windows Terminal` 中一次选择多台服务器,批量登录,并支持批量执行预先指定的命令。 - -- 按下 `Space`、`Ctrl+X` 等可以选中或取消当前服务器,若不能选中说明还不支持当前终端,请先运行 `tmux`。 - -- 按下 `Ctrl+P` 会以分屏的方式批量登录,`Ctrl+W` 会打开新窗口批量登录,`Ctrl+T` 会打开新 tab 批量登录。 - -- `tssh` 不带参数启动可以批量登录服务器,若带 `-o RemoteCommand` 参数启动则可以批量执行指定的命令。支持执行指定命令之后进入交互式 shell,但 `Windows Terminal` 不支持分号 `;`,可以用 `|cat&&` 代替。举例: - - ```sh - tssh -t -o RemoteCommand='ping -c3 trzsz.github.io ; bash' - tssh -t -o RemoteCommand="ping -c3 trzsz.github.io |cat&& bash" - ``` - -## 分组标签 - -- 如果服务器数量很多,分组标签 `GroupLabels` 可以在按 `/` 搜索时,快速找到目标服务器。 - -- 按 `/` 输入分组标签后,`回车`可以锁定;再按 `/` 可以输入另一个分组标签,`回车`再次锁定。 - -- 在非搜索模式下,按 `E` 可以清空当前搜索标签;在搜索模式下按 `Ctrl + E` 也是同样效果。 - -- 支持在一个 `GroupLabels` 中以空格分隔,配置多个分组标签;支持配置多个 `GroupLabels`。 - -- 支持以通配符 \* 的形式,在多个 Host 节点配置分组标签,`tssh` 会将所有的标签汇总起来。 - - ``` - # 以下 testAA 具有标签 group1 group2 label3 label4 group5,可以加上 `#!!` 前缀,以兼容标准 ssh - Host test* - #!! GroupLabels group1 group2 - #!! GroupLabels label3 - Host testAA - #!! GroupLabels label4 group5 - ``` - -## 自动交互 - -- 支持类似 `expect` 的自动交互功能,可以在登录服务器之后,自动匹配服务器的输出,然后自动输入。 - - ``` - Host auto - #!! ExpectCount 5 # 配置自动交互的次数,默认是 0 即无自动交互 - #!! ExpectTimeout 30 # 配置自动交互的超时时间(单位:秒),默认是 30 秒 - #!! ExpectPattern1 *assword # 配置第一个自动交互的匹配表达式 - # 配置第一个自动输入(密文),这是由 tssh --enc-secret 编码得到的字符串,tssh 会自动发送 \r 回车 - #!! ExpectSendPass1 d7983b4a8ac204bd073ed04741913befd4fbf813ad405d7404cb7d779536f8b87e71106d7780b2 - #!! ExpectPattern2 hostname*$ # 配置第二个自动交互的匹配表达式 - #!! ExpectSendText2 echo tssh expect\r # 配置第二个自动输入(明文),需要指定 \r 才会发送回车 - # 以上 ExpectSendPass? 和 ExpectSendText? 只要二选一即可,若都配置则 ExpectSendPass? 的优先级更高 - # -------------------------------------------------- - # 在每个 ExpectPattern 匹配之前,可以配置一个或多个可选的匹配,用法如下: - #!! ExpectPattern3 hostname*$ # 配置第三个自动交互的匹配表达式 - #!! ExpectSendText3 ssh xxx\r # 配置第三个自动输入,也可以换成 ExpectSendPass3 然后配置密文 - #!! ExpectCaseSendText3 yes/no y\r # 在 ExpectPattern3 匹配之前,若遇到 yes/no 则发送 y 并回车 - #!! ExpectCaseSendText3 y/n yes\r # 在 ExpectPattern3 匹配之前,若遇到 y/n 则发送 yes 并回车 - #!! ExpectCaseSendPass3 token d7... # 在 ExpectPattern3 匹配之前,若遇到 token 则解码 d7... 并发送 - # -------------------------------------------------- - #!! ExpectPattern4 token: # 配置第四个自动交互的匹配表达式(这里以动态密码举例) - #!! ExpectSendOtp4 oathtool --totp -b xxxxx # 配置获取动态密码的命令(明文) - #!! ExpectPattern5 token: # 配置第五个自动交互的匹配表达式(这里以动态密码举例) - # 下面是运行 tssh --enc-secret 输入命令 oathtool --totp -b xxxxx 得到的密文串 - #!! ExpectSendEncOtp5 77b4ce85d087b39909e563efb165659b22b9ea700a537f1258bdf56ce6fdd6ea70bc7591ea5c01918537a65433133bc0bd5ed3e4 - ``` - - - 配置 `ExpectCount` 大于 `0` 之后,使用 `tssh --debug` 登录,可以看到 `expect` 捕获到的输出。 - -## 记住密码 - -- 为了兼容标准 ssh ,密码可以单独配置在 `~/.ssh/password` 中,也可以在 `~/.ssh/config` 中加上 `#!!` 前缀。 - -- 推荐使用前面公钥认证的方式,密码的安全性弱一些。如果必须要用密码,建议至少设置好权限,如: - - ```sh - chmod 700 ~/.ssh && chmod 600 ~/.ssh/password ~/.ssh/config - ``` - -- 下面配置 `test1` 和 `test2` 的密码是 `123456`,其他以 `test` 开头的密码是 `111111`: - - ``` - # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh - Host test1 - # 下面是运行 tssh --enc-secret 输入密码 123456 得到的密文串,每次运行结果不同。 - #!! encPassword 756b17766f45bdc44c37f811db9990b0880318d5f00f6531b15e068ef1fde2666550 - - # 如果配置在 ~/.ssh/password 中,则不需要考虑是否兼容标准 ssh - Host test2 - # 下面是运行 tssh --enc-secret 输入密码 123456 得到的密文串,每次运行结果不同。 - encPassword 051a2f0fdc7d0d40794b845967df4c2d05b5eb0f25339021dc4e02a9d7620070654b - - # ~/.ssh/config 和 ~/.ssh/password 是支持通配符的,tssh 会使用第一个匹配到的值。 - # 这里希望 test2 使用区别于其他 test* 的密码,所以将 test* 放在了 test2 的后面。 - - Host test* - Password 111111 # 支持明文密码,但是推荐使用 tssh --enc-secret 简单加密一下。 - ``` - -- 如果启用了 `ControlMaster` 多路复用,或者是在 `Warp` 终端,需要使用前面 `自动交互` 的方式实现记住密码的效果。配置方式请参考前面 `自动交互`,加上 `Ctrl` 前缀即可,如: - - ``` - Host ctrl - #!! CtrlExpectCount 1 # 配置自动交互的次数,一般只要输入一次密码 - #!! CtrlExpectPattern1 *assword # 配置密码提示语的匹配表达式 - #!! CtrlExpectSendPass1 d7983b... # 配置 tssh --enc-secret 编码后的密码 - ``` - -- 支持记住私钥的`Passphrase`( 推荐使用 `ssh-agent` )。支持与 `IdentityFile` 一起配置, 支持使用私钥文件名代替 Host 别名设置通用密钥的 `Passphrase`。举例: - - ``` - # IdentityFile 和 Passphrase 一起配置,可以加上 `#!!` 前缀,以兼容标准 ssh - Host test1 - IdentityFile /path/to/id_rsa - # 下面是运行 tssh --enc-secret 输入密码 123456 得到的密文串,每次运行结果不同。 - #!! encPassphrase 6f419911555b0cdc84549ae791ef69f654118d734bb4351de7e83163726ef46d176a - - # 在 ~/.ssh/config 中配置通用私钥 ~/.ssh/id_ed25519 对应的 Passphrase - # 可以加上通配符 * 以避免 tssh 搜索和选择时,文件名出现在服务器列表中。 - Host id_ed25519* - # 下面是运行 tssh --enc-secret 输入密码 111111 得到的密文串,每次运行结果不同。 - #!! encPassphrase 3a929328f2ab1be0ba3fccf29e8125f8e2dac6dab73c946605cf0bb8060b05f02a68 - - # 在 ~/.ssh/password 中配置则不需要通配符*,也不会出现在服务器列表中。 - Host id_rsa - Passphrase 111111 # 支持明文密码,但是推荐使用 tssh --enc-secret 简单加密一下。 - ``` - -## 记住答案 - -- 除了私钥和密码,还有一种登录方式,英文叫 keyboard interactive ,是服务器返回一些问题,客户端提供正确的答案就能登录,很多自定义的一次性密码就是利用这种方式实现的。 - -- 对于只有一个问题,且答案(密码)固定不变的,只要配置 `QuestionAnswer1` 即可。对于有多个问题的,可以按问题的序号进行配置,也可以按问题的 hex 编码进行配置。 - -- 使用 `tssh --debug` 登录,会输出问题的 hex 编码,从而知道该如何使用 hex 编码进行配置。配置举例: - - ``` - # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh - Host test1 - # 下面是运行 tssh --enc-secret 输入答案 `答案一` 得到的密文串,每次运行结果不同。 - encQuestionAnswer1 482de7690ccc5229299ccadd8de1cb7c6d842665f0dc92ff947a302f644817baecbab38601 - Host test2 - # 下面是运行 tssh --enc-secret 输入答案 `答案一` 得到的密文串,每次运行结果不同。 - encQuestionAnswer1 43e86f1140cf6d8c786248aad95a26f30633f1eab671676b0860ecb5b1a64fb3ec5212dddf - QuestionAnswer2 答案二 # 支持明文答案,但是推荐使用 tssh --enc-secret 简单加密一下。 - QuestionAnswer3 答案三 - Host test3 - # 其中 `6e616d653a20` 是问题 `name: ` 的 hex 编码,`enc` 前缀代表配置的是密文串。 - # 下面是运行 tssh --enc-secret 输入答案 `my_name` 得到的密文串,每次运行结果不同。 - enc6e616d653a20 775f2523ab747384e1661aba7779011cb754b73f2e947672c7fd109607b801d70902d1 - 636f64653a20 my_code # 其中 `636f64653a20` 是问题 `code: ` 的 hex 编码, `my_code` 是明文答案 - ``` - -- 对于可以通过命令行获取到的动态密码,则可以如下配置(同样支持按序号或 hex 编码进行配置): - - ``` - Host otp - OtpCommand1 oathtool --totp -b xxxxx # 按序号配置获取动态密码的命令 - otp636f64653a20 oathtool --totp -b xxxxx # 按 `code: ` 的 hex 编码 `636f64653a20` 配置获取动态密码的命令 - # 下面是运行 tssh --enc-secret 输入命令 oathtool --totp -b xxxxx 得到的密文串,加上 `enc` 前缀进行配置 - encOtpCommand2 77b4ce85d087b39909e563efb165659b22b9ea700a537f1258bdf56ce6fdd6ea70bc7591ea5c01918537a65433133bc0bd5ed3e4 - encotp636f64653a20 77b4ce85d087b39909e563efb165659b22b9ea700a537f1258bdf56ce6fdd6ea70bc7591ea5c01918537a65433133bc0bd5ed3e4 - ``` - -- 如果启用了 `ControlMaster` 多路复用,或者是在 `Warp` 终端,请参考前面 `自动交互` 加 `Ctrl` 前缀来实现。 - - ``` - Host ctrl_otp - #!! CtrlExpectCount 1 # 配置自动交互的次数,一般只要输入一次密码 - #!! CtrlExpectPattern1 token: # 配置密码提示语的匹配表达式(这里以动态密码举例) - #!! CtrlExpectSendOtp1 oathtool --totp -b xxxxx # 配置获取动态密码的命令(明文) - #!! CtrlExpectSendEncOtp1 77b4ce85d0... # 或者配置 tssh --enc-secret 得到的密文串 - ``` - -## 可选配置 - -- 支持在 `~/.tssh.conf`( Windows 是 `C:\Users\your_name\.tssh.conf` )中进行以下自定义配置: - - ``` - # SSH 配置路径,默认为 ~/.ssh/config - ConfigPath = ~/.ssh/config - - # 扩展配置路径,默认为 ~/.ssh/password - ExConfigPath = ~/.ssh/password - - # trz 上传时,对话框打开的路径,为空时打开上次的路径, 默认为空 - DefaultUploadPath = ~/Downloads - - # tsz 下载时,自动保存的路径,为空时弹出对话框手工选择,默认为空 - DefaultDownloadPath = ~/Downloads - - # tssh 搜索和选择服务器时,每页显示的记录数,默认为 10 - PromptPageSize = 10 - - # tssh 搜索和选择服务器时,默认是类似 vim 的 normal 模式,想默认进入搜索模式可如下配置: - PromptDefaultMode = search - - # tssh 搜索和选择服务器时,详情中显示的配置列表,默认如下: - PromptDetailItems = Alias Host Port User GroupLabels IdentityFile ProxyCommand ProxyJump RemoteCommand - - # tssh 搜索和选择服务器时,可以自定义光标和选中的图标: - PromptCursorIcon = 🧨 - PromptSelectedIcon = 🍺 - - # 登录后自动设置终端标题,退出后不会重置,你需要参考下文在本地 shell 中设置 PROMPT_COMMAND - SetTerminalTitle = Yes - ``` - -## 其他功能 - -- 使用 `-f` 后台运行时,可以加上 `--reconnect` 参数,在后台进程因连接断开等而退出时,会自动重新连接。 - -- 使用 `--dragfile` 启用拖拽上传功能,想默认启用则可以在 `~/.ssh/config` 或 `ExConfigPath` 中配置: - - ``` - Host * - # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh - EnableDragFile Yes - ``` - -- 使用 `--zmodem` 启用 `rz / sz` 功能,想默认启用则可以在 `~/.ssh/config` 或 `ExConfigPath` 中配置: - - ``` - Host server0 - # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh - EnableZmodem Yes - ``` - - - 需要在客户端( 本地电脑 )上安装 `lrzsz`,Windows 可以从 [lrzsz-win32](https://github.com/trzsz/lrzsz-win32/releases) 下载解压并加到 `PATH` 中,也可以如下安装: - - ``` - scoop install https://trzsz.github.io/lrzsz.json - - choco install lrzsz --version=0.12.21 - ``` - - - 关于 `rz / sz` 进度条,己传大小和传输速度会有一点偏差,它的主要作用只是指示传输正在进行中。 - -- 使用 `-oEnableTrzsz=No` 禁用 trzsz 功能,想默认禁用则可以在 `~/.ssh/config` 或 `ExConfigPath` 中配置: - - ``` - Host server1 - # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh - EnableTrzsz No - ``` - -- 上文说的“记住密码”和“记住答案”,只要在配置项前面加上 `enc` 则可以配置密文,防止被人窥屏。并且,密文可以解决密码含有`#`的问题。 - - - 运行 `tssh --enc-secret`,输入密码或答案,可得到用于配置的密文( 相同密码每次运行结果不同 ): - - ``` - Host server2 - # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh - encPassword de88c4dbdc95d85303682734e2397c4d8dd29bfff09ec53580f31dd40291fc8c7755 - encQuestionAnswer1 93956f6e7e9f2aef3af7d6a61f7046dddf14aa4bbd9845dbb836fe3782b62ac0d89f - ``` - -- 运行 `tssh --new-host` 可以在 TUI 界面轻松添加 SSH 配置,并且完成后可以立即登录。 - -- 运行 `tssh --install-trzsz` 可以将 [trzsz](https://github.com/trzsz/trzsz-go) ( `trz` / `tsz` ) 安装到服务器上。 - - - 默认安装到 `~/.local/bin/` 目录,可以通过 `--install-path /path/to/install` 指定安装目录。 - - 若 `--install-path` 安装目录含有 `~/`,则必须加上单引号,如`--install-path '~/path'`。 - - 若获取 `trzsz` 的最新版本号失败,可以通过 `--trzsz-version x.x.x` 参数自行指定。 - - 若下载 `trzsz` 的安装包失败,可以自行下载并通过 `--trzsz-bin-path /path/to/trzsz.tar.gz` 参数指定。 - - 注意:`--install-trzsz` 不支持 Windows 服务器,不支持跳板机( 除非以 `ProxyJump` 跳过 )。 - -- 关于修改终端标题,其实无需 `tssh` 就能实现,只要在服务器的 shell 配置文件中(如`~/.bashrc`)配置: - - ```sh - # 设置固定的服务器标题 - PROMPT_COMMAND='echo -ne "\033]0;固定的服务器标题\007"' - - # 根据环境变量动态变化的标题 - PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"' - ``` - - - 如果在 `~/.tssh.conf` 中设置了 `SetTerminalTitle = Yes`,则会在登录后自动设置终端标题,但是服务器上的 `PROMPT_COMMAND` 会覆盖 `tssh` 设置的标题。 - - 在 `tssh` 退出后不会重置为原来的标题,你需要在本地 shell 中设置 `PROMPT_COMMAND`,让它覆盖 `tssh` 设置的标题。 - -## 快捷键 - -| 操作 | 全局快捷键 | 非搜索快捷键 | 快捷键描述 | -| --------- | ------------------------------- | ------------ | --------------- | -| Confirm | Enter | | 确认并登录 | -| Quit/Exit | Ctrl+C Ctrl+Q | q Q | 取消并退出 | -| Move Prev | Ctrl+K Shift+Tab ↑ | k K | 往上移光标 | -| Move Next | Ctrl+J Tab ↓ | j J | 往下移光标 | -| Page Up | Ctrl+H Ctrl+U Ctrl+B PageUp ← | h H u U b B | 往上翻一页 | -| Page Down | Ctrl+L Ctrl+D Ctrl+F PageDown → | l L d D f F | 往下翻一页 | -| Goto Home | Home | g | 跳到第一行 | -| Goto End | End | G | 跳到最尾行 | -| EraseKeys | Ctrl+E | e E | 擦除搜索关键字 | -| TglSearch | / | | 切换搜索功能 | -| Tgl Help | ? | | 切换帮助信息 | -| TglSelect | Ctrl+X Ctrl+Space Alt+Space | Space x X | 切换选中状态 | -| SelectAll | Ctrl+A | a A | 全选当前页 | -| SelectOpp | Ctrl+O | o O | 反选当前页 | -| Open Wins | Ctrl+W | w W | 新窗口批量登录 | -| Open Tabs | Ctrl+T | t T | 新 Tab 批量登录 | -| Open Pane | Ctrl+P | p P | 分屏批量登录 | - -## 故障排除 - -- 在 Warp 终端,分块 Blocks 的功能需要将 `tssh` 重命名为 `ssh`,推荐建个软链接( 对更新友好 ): - - ``` - sudo ln -sv $(which tssh) /usr/local/bin/ssh - ``` - - - 软链后,`ssh -V` 应输出 `trzsz ssh` 加版本号,如果不是,说明软链不成功,或者在 `PATH` 中 `openssh` 的优先级更高,你要软链到另一个地方或者调整 `PATH` 的优先级。 - - - 软链后,要直接使用 `ssh`,它等价于 `tssh`。如果还是用 `tssh` 是不会支持分块 Blocks 功能的。 +- Download from the [Releases](https://github.com/trzsz/trzsz-ssh/releases) - - `--dragfile` 参数可能会让 Warp 分块功能失效,请参考前文配置 `EnableDragFile` 来启用拖拽功能。 +## Contributing - - 拖拽文件或目录进入 Warp 终端后,可能不会立即触发上传,需要多按一次`回车`键,才会上传。 +Welcome and thank you for considering contributing. We appreciate all forms of support, from coding and testing to documentation and CI/CD improvements. -- 如果你在使用 Windows7 或者旧版本的 Windows10 等,遇到 `enable virtual terminal failed` 的错误。 +- Fork and clone the repository `https://github.com/trzsz/trzsz-ssh.git`. - - 可以尝试在 [Cygwin](https://www.cygwin.com/)、[MSYS2](https://www.msys2.org/) 或 [Git Bash](https://www.atlassian.com/git/tutorials/git-bash) 内使用 `tssh`。 +- Make your changes just don't break or fix the unit tests `go test ./tssh`. -- 如果在 `~/.ssh/config` 中配置了 `tssh` 特有的配置项后,标准 `ssh` 报错 `Bad configuration option`。 +- Build the binary `go build -o ./bin/ ./cmd/tssh` and test it `./bin/tssh`. - - 可以在出错配置项中加上前缀 `#!!`,标准 `ssh` 会将它当作注释,而 `tssh` 则会认为它是有效配置之一。 +- Once you are happy with your changes, please submit a pull request. -## 录屏演示 +## Screenshot -![tssh登录演示](https://trzsz.github.io/images/tssh.gif) +![tssh login demo](https://trzsz.github.io/images/tssh.gif) -![tssh批量执行](https://trzsz.github.io/images/batch_ssh.gif) +![tssh batch login](https://trzsz.github.io/images/batch_ssh.gif) -## 联系方式 +## Contact -有什么问题可以发邮件给作者 ,也可以提 [Issues](https://github.com/trzsz/trzsz-ssh/issues) 。欢迎加入 QQ 群:318578930。 +Feel free to email the author , or create an [issue](https://github.com/trzsz/trzsz-ssh/issues). Welcome to join the QQ group: 318578930. -## 赞助打赏 +## Sponsor -[❤️ 赞助 trzsz ❤️](https://github.com/trzsz),请作者喝杯咖啡 ☕ ? 谢谢您们的支持! +[❤️ Sponsor trzsz ❤️](https://github.com/trzsz), buy the author a drink 🍺 ? Thank you for your support!