diff --git a/cn/ssh.md b/cn/ssh.md index 003fbbf..0b64f47 100644 --- a/cn/ssh.md +++ b/cn/ssh.md @@ -15,17 +15,17 @@ GitHub: [https://github.com/trzsz/trzsz-ssh](https://github.com/trzsz/trzsz-ssh) ## tssh 简介 -你喜欢的 ssh 终端是否有好用的服务器管理功能?是否支持记住密码?是否有好用的文件传输工具? +- 你喜欢的 ssh 终端是否有好用的服务器管理功能?是否支持记住密码?是否有好用的文件传输工具? -tssh 支持选择或搜索 `~/.ssh/config` 中配置的服务器,支持 vim 操作习惯,解决 ssh 终端的服务器管理问题。 +- tssh 支持选择或搜索 `~/.ssh/config` 中配置的服务器,支持 vim 操作习惯,解决 ssh 终端的服务器管理问题。 -tssh 支持一次选择多台服务器,批量登录,并支持批量执行预先指定的命令,方便快速完成批量服务器操作。 +- tssh 支持一次选择多台服务器,批量登录,并支持批量执行预先指定的命令,方便快速完成批量服务器操作。 -tssh 支持配置服务器登录密码,解决每次手工输入密码的麻烦( 在自己能控制的服务器,推荐使用公私钥登录 )。 +- tssh 支持配置服务器登录密码,解决每次手工输入密码的麻烦( 在自己能控制的服务器,推荐使用公私钥登录 )。 -tssh 内置支持 [trzsz](https://trzsz.github.io/cn/) ( trz / tsz ) 文件传输工具,一并解决了 Windows 中使用 `trzsz ssh` 上传速度很慢的问题。 +- tssh 内置支持 [trzsz](https://trzsz.github.io/cn/) ( trz / tsz ) 文件传输工具,一并解决了 Windows 中使用 `trzsz ssh` 上传速度很慢的问题。 -_在作者的 MacOS 上,使用 `trzsz ssh` 的上传速度在 10 MB/s 左右,而使用 `tssh` 可以到 80 MB/s 以上。_ +- _在作者的 MacOS 上,使用 `trzsz ssh` 的上传速度在 10 MB/s 左右,而使用 `tssh` 可以到 80 MB/s 以上。_ ## 安装方法 @@ -168,11 +168,11 @@ _`~/` 代表 HOME 目录。在 Windows 中,请将下文的 `~/` 替换成 `C:\ - 登录服务器,将公钥( 即前面生成密钥对时 `.pub` 后缀的文件内容 )追加写入服务器上的 `~/.ssh/authorized_keys` 文件中。 - 一行代表一个客户端的公钥,注意 `~/.ssh/authorized_keys` 要设置正确的权限: + - 一行代表一个客户端的公钥,注意 `~/.ssh/authorized_keys` 要设置正确的权限: - ```sh - chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys - ``` + ```sh + chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys + ``` - 在客户端配置好 `~/.ssh/config` 文件,举例: @@ -227,14 +227,39 @@ _`~/` 代表 HOME 目录。在 Windows 中,请将下文的 `~/` 替换成 `C:\ #!! GroupLabels label4 group5 ``` +## 自动交互 + +- 支持类似 `expect` 的自动交互功能,可以在登录服务器之后,自动匹配服务器的输出,然后自动输入。 + + ``` + Host auto + #!! ExpectCount 3 # 配置自动交互的次数,默认是 0 即无自动交互 + #!! ExpectTimeout 30 # 配置自动交互的超时时间(单位:秒),默认是 30 秒 + #!! ExpectPattern1 *assword # 配置第一个自动交互的匹配表达式 + # 配置第一个自动输入(密文),填 tssh --enc-secret 编码后的字符串,会自动发送 \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... + ``` + + - 使用 `tssh --debug` 登录,可以看到 `expect` 捕获到的输出,以及其匹配结果和自动输入的交互。 + ## 记住密码 - 为了兼容标准 ssh ,密码可以单独配置在 `~/.ssh/password` 中,也可以在 `~/.ssh/config` 中加上 `#!!` 前缀。 -- 推荐使用前面密钥认证的方式,密码的安全性弱一些。如果必须要用密码,建议设置好 `~/.ssh/password` 的权限,如: +- 推荐使用前面公钥认证的方式,密码的安全性弱一些。如果必须要用密码,建议至少设置好权限,如: ```sh - chmod 700 ~/.ssh && chmod 600 ~/.ssh/password + chmod 700 ~/.ssh && chmod 600 ~/.ssh/password ~/.ssh/config ``` - 下面配置 `test1` 和 `test2` 的密码是 `123456`,其他以 `test` 开头的密码是 `111111`: @@ -242,17 +267,28 @@ _`~/` 代表 HOME 目录。在 Windows 中,请将下文的 `~/` 替换成 `C:\ ``` # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh Host test1 - #!! Password 123456 + # 下面是运行 tssh --enc-secret 输入密码 123456 得到的密文串,每次运行结果不同。 + #!! encPassword 756b17766f45bdc44c37f811db9990b0880318d5f00f6531b15e068ef1fde2666550 # 如果配置在 ~/.ssh/password 中,则不需要考虑是否兼容标准 ssh Host test2 - Password 123456 + # 下面是运行 tssh --enc-secret 输入密码 123456 得到的密文串,每次运行结果不同。 + encPassword 051a2f0fdc7d0d40794b845967df4c2d05b5eb0f25339021dc4e02a9d7620070654b # ~/.ssh/config 和 ~/.ssh/password 是支持通配符的,tssh 会使用第一个匹配到的值。 # 这里希望 test2 使用区别于其他 test* 的密码,所以将 test* 放在了 test2 的后面。 Host test* - Password 111111 + 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`。举例: @@ -261,16 +297,18 @@ _`~/` 代表 HOME 目录。在 Windows 中,请将下文的 `~/` 替换成 `C:\ # IdentityFile 和 Passphrase 一起配置,可以加上 `#!!` 前缀,以兼容标准 ssh Host test1 IdentityFile /path/to/id_rsa - #!! Passphrase 123456 + # 下面是运行 tssh --enc-secret 输入密码 123456 得到的密文串,每次运行结果不同。 + #!! encPassphrase 6f419911555b0cdc84549ae791ef69f654118d734bb4351de7e83163726ef46d176a # 在 ~/.ssh/config 中配置通用私钥 ~/.ssh/id_ed25519 对应的 Passphrase # 可以加上通配符 * 以避免 tssh 搜索和选择时,文件名出现在服务器列表中。 Host id_ed25519* - #!! Passphrase 111111 + # 下面是运行 tssh --enc-secret 输入密码 111111 得到的密文串,每次运行结果不同。 + #!! encPassphrase 3a929328f2ab1be0ba3fccf29e8125f8e2dac6dab73c946605cf0bb8060b05f02a68 # 在 ~/.ssh/password 中配置则不需要通配符*,也不会出现在服务器列表中。 Host id_rsa - Passphrase 111111 + Passphrase 111111 # 支持明文密码,但是推荐使用 tssh --enc-secret 简单加密一下。 ``` ## 记住答案 @@ -284,16 +322,22 @@ _`~/` 代表 HOME 目录。在 Windows 中,请将下文的 `~/` 替换成 `C:\ ``` # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh Host test1 - QuestionAnswer1 答案一 + # 下面是运行 tssh --enc-secret 输入答案 `答案一` 得到的密文串,每次运行结果不同。 + encQuestionAnswer1 482de7690ccc5229299ccadd8de1cb7c6d842665f0dc92ff947a302f644817baecbab38601 Host test2 - QuestionAnswer1 答案一 - QuestionAnswer2 答案二 + # 下面是运行 tssh --enc-secret 输入答案 `答案一` 得到的密文串,每次运行结果不同。 + encQuestionAnswer1 43e86f1140cf6d8c786248aad95a26f30633f1eab671676b0860ecb5b1a64fb3ec5212dddf + QuestionAnswer2 答案二 # 支持明文答案,但是推荐使用 tssh --enc-secret 简单加密一下。 QuestionAnswer3 答案三 Host test3 - 6e616d653a20 my_name # 其中 `6e616d653a20` 是问题 `name: ` 的 hex 编码 - 636f64653a20 my_code # 其中 `636f64653a20` 是问题 `code: ` 的 hex 编码 + # 其中 `6e616d653a20` 是问题 `name: ` 的 hex 编码,`enc` 前缀代表配置的是密文串。 + # 下面是运行 tssh --enc-secret 输入答案 `my_name` 得到的密文串,每次运行结果不同。 + enc6e616d653a20 775f2523ab747384e1661aba7779011cb754b73f2e947672c7fd109607b801d70902d1 + 636f64653a20 my_code # 其中 `636f64653a20` 是问题 `code: ` 的 hex 编码, `my_code` 是明文答案 ``` +- 如果启用了 `ControlMaster` 多路复用,或者是在 `Warp` 终端,请参考前面 `自动交互` 加 `Ctrl` 前缀来实现。 + ## 可选配置 - 支持在 `~/.tssh.conf`( Windows 是 `C:\Users\your_name\.tssh.conf` )中进行以下自定义配置: @@ -314,15 +358,21 @@ _`~/` 代表 HOME 目录。在 Windows 中,请将下文的 `~/` 替换成 `C:\ # tssh 搜索和选择服务器时,每页显示的记录数,默认为 10 PromptPageSize = 10 + # tssh 搜索和选择服务器时,默认是类似 vim 的 normal 模式,想默认进入搜索模式可如下配置: + PromptDefaultMode = search + # tssh 搜索和选择服务器时,详情中显示的配置列表,默认如下: PromptDetailItems = Alias Host Port User GroupLabels IdentityFile ProxyCommand ProxyJump RemoteCommand + + # 登录后自动设置终端标题,退出后不会重置,你需要参考下文在本地 shell 中设置 PROMPT_COMMAND + SetTerminalTitle = Yes ``` ## 其他功能 -- 使用 `-f` 后台运行时,可以一并加上 `--reconnect` 参数,这样在后台进程因连接断开等而退出时,会自动重新连接。 +- 使用 `-f` 后台运行时,可以加上 `--reconnect` 参数,在后台进程因连接断开等而退出时,会自动重新连接。 -- 使用 `--dragfile` 启用拖拽上传功能,想默认启用则可以在 `~/.ssh/config` 或扩展配置 `ExConfigPath` 中配置: +- 使用 `--dragfile` 启用拖拽上传功能,想默认启用则可以在 `~/.ssh/config` 或 `ExConfigPath` 中配置: ``` Host * @@ -330,7 +380,7 @@ _`~/` 代表 HOME 目录。在 Windows 中,请将下文的 `~/` 替换成 `C:\ EnableDragFile Yes ``` -- 使用 `--zmodem` 启用 `rz / sz` 功能,想默认启用则可以在 `~/.ssh/config` 或扩展配置 `ExConfigPath` 中配置: +- 使用 `--zmodem` 启用 `rz / sz` 功能,想默认启用则可以在 `~/.ssh/config` 或 `ExConfigPath` 中配置: ``` Host server0 @@ -340,15 +390,15 @@ _`~/` 代表 HOME 目录。在 Windows 中,请将下文的 `~/` 替换成 `C:\ - 需要在客户端( 本地电脑 )上安装 `lrzsz`,Windows 可以从 [lrzsz-win32](https://github.com/trzsz/lrzsz-win32/releases) 下载解压并加到 `PATH` 中,也可以如下安装: - ``` - scoop install https://trzsz.github.io/lrzsz.json + ``` + scoop install https://trzsz.github.io/lrzsz.json - choco install lrzsz --version=0.12.21 - ``` + choco install lrzsz --version=0.12.21 + ``` - - 关于进度条,己传文件大小和传输速度不是精确值,会有一些偏差,它的主要作用只是指示传输正在进行中。 + - 关于 `rz / sz` 进度条,己传大小和传输速度会有一点偏差,它的主要作用只是指示传输正在进行中。 -- 使用 `-oEnableTrzsz=No` 禁用 trzsz 功能,想默认禁用则可以在 `~/.ssh/config` 或扩展配置 `ExConfigPath` 中配置: +- 使用 `-oEnableTrzsz=No` 禁用 trzsz 功能,想默认禁用则可以在 `~/.ssh/config` 或 `ExConfigPath` 中配置: ``` Host server1 @@ -356,9 +406,9 @@ _`~/` 代表 HOME 目录。在 Windows 中,请将下文的 `~/` 替换成 `C:\ EnableTrzsz No ``` -- 上文说的“记住密码”和“记住答案”,只要在配置项前面加上 `enc` 则可以配置密文,防止被人窥屏。密文可以解决密码含有`#`的问题。 +- 上文说的“记住密码”和“记住答案”,只要在配置项前面加上 `enc` 则可以配置密文,防止被人窥屏。并且,密文可以解决密码含有`#`的问题。 - 运行 `tssh --enc-secret`,输入密码或答案的明文,可得到用于配置的密文( 相同密码每次加密的结果不同 ): + - 运行 `tssh --enc-secret`,输入密码或答案,可得到用于配置的密文( 相同密码每次运行结果不同 ): ``` Host server2 @@ -369,7 +419,26 @@ _`~/` 代表 HOME 目录。在 Windows 中,请将下文的 `~/` 替换成 `C:\ - 运行 `tssh --new-host` 可以在 TUI 界面轻松添加 SSH 配置,并且完成后可以立即登录。 -- 运行 `tssh --install-trzsz` 可以自动安装 [trzsz](https://github.com/trzsz/trzsz-go) 到服务器的 `~/.local/bin/` 目录。若获取 `trzsz` 的最新版本号失败,可以通过 `--trzsz-version x.x.x` 参数自行指定。若下载 `trzsz` 的安装包失败,可以自行下载并通过 `--trzsz-bin-path /path/to/trzsz.tar.gz` 参数指定。 +- 运行 `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` 设置的标题。 ## 快捷键 @@ -401,6 +470,10 @@ _`~/` 代表 HOME 目录。在 Windows 中,请将下文的 `~/` 替换成 `C:\ sudo ln -sv $(which tssh) /usr/local/bin/ssh ``` + - 软链后,`ssh -V` 应输出 `trzsz ssh` 加版本号,如果不是,说明软链不成功,或者在 `PATH` 中 `openssh` 的优先级更高,你要软链到另一个地方或者调整 `PATH` 的优先级。 + + - 软链后,要直接使用 `ssh`,它等价于 `tssh`。如果还是用 `tssh` 是不会支持分块 Blocks 功能的。 + - `--dragfile` 参数可能会让 Warp 分块功能失效,请参考前文配置 `EnableDragFile` 来启用拖拽功能。 - 拖拽文件或目录进入 Warp 终端后,可能不会立即触发上传,需要多按一次`回车`键,才会上传。 diff --git a/ssh.md b/ssh.md index 52450b2..deda9b4 100644 --- a/ssh.md +++ b/ssh.md @@ -13,17 +13,17 @@ GitHub: [https://github.com/trzsz/trzsz-ssh](https://github.com/trzsz/trzsz-ssh) ## Introduce -Does your favorite ssh terminal have server management feature? Does it support remembering password? Does it have a cool file transfer tool? +- 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 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 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 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. +- 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._ +- _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 @@ -223,14 +223,39 @@ _`~/` represents the HOME directory. Please replace `~/` below with `C:\Users\yo #!! 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 3 # 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). Fill in the string encoded by tssh --enc-secret, it will automatically send \r (enter) + #!! 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 and send d7... + ``` + + - Use `tssh --debug` to log in, you can see the output captured by `expect`, as well as the interaction between its matching results and automated input. + ## 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 of `~/.ssh/password`: +- 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 + 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`: @@ -238,17 +263,28 @@ _`~/` represents the HOME directory. Please replace `~/` below with `C:\Users\yo ``` # If configured in ~/.ssh/config, you can add `#!!` prefix to be compatible with openssh. Host test1 - #!! Password 123456 + # 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 - Password 123456 + # 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 + 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, generally only needing to enter 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: @@ -257,16 +293,18 @@ _`~/` represents the HOME directory. Please replace `~/` below with `C:\Users\yo # Configuring Passphrase together with IdentityFile. Add `#!!` prefix to be compatible with openssh. Host test1 IdentityFile /path/to/id_rsa - #!! Passphrase 123456 + # 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* - #!! Passphrase 111111 + # 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 + Passphrase 111111 # supports plain text, but it is recommended to encrypt with `tssh --enc-secret`. ``` ## Remember Answers @@ -280,16 +318,22 @@ _`~/` represents the HOME directory. Please replace `~/` below with `C:\Users\yo ``` # If configured in ~/.ssh/config, add `#!!` prefix to be compatible with openssh. Host test1 - QuestionAnswer1 TheAnswer1 + # The following ciphertext was generated by encoding `TheAnswer1` with `tssh --enc-secret`. + encQuestionAnswer1 4f6b79d0e4e48fc56ee29c61bd19559a322cd07f7d27f2a7f33978671be1b522d549252b22ee Host test2 - QuestionAnswer1 TheAnswer1 - QuestionAnswer2 TheAnswer2 + # 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 - 6e616d653a20 my_name # The `6e616d653a20` is the hex code of `name: ` - 636f64653a20 my_code # The `636f64653a20` is the hex code of `code: ` + # 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. ``` +- If `ControlMaster` multiplexing is enabled or using `Warp` terminal, you will need to use the `Automated Interaction` mentioned earlier to achieve remembering answers. + ## Configuration - The following custom configurations are supported in `~/.tssh.conf` (`C:\Users\your_name\.tssh.conf` on Windows): @@ -310,13 +354,19 @@ _`~/` represents the HOME directory. Please replace `~/` below with `C:\Users\yo # When tssh searches and selects a server, the number of records displayed on each page, the default is 10. PromptPageSize = 10 + # When tssh searches and selects a server, default is normal mode similar to vim. Configure to search mode as follows: + PromptDefaultMode = search + # When tssh searches and selects a server, the items displayed in details. The default is as follows: PromptDetailItems = Alias Host Port User GroupLabels IdentityFile ProxyCommand ProxyJump RemoteCommand + + # 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 also add `--reconnect`, it will automatically reconnect when the background process exits. +- 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`: @@ -336,13 +386,13 @@ _`~/` represents the HOME directory. Please replace `~/` below with `C:\Users\yo - `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 + ``` + scoop install https://trzsz.github.io/lrzsz.json - choco install lrzsz --version=0.12.21 - ``` + choco install lrzsz --version=0.12.21 + ``` - - About the progress, the transferred and speed are not precise, there will be some deviation. It just indicating that the transfer is in progress. + - 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`: @@ -365,7 +415,26 @@ _`~/` represents the HOME directory. Please replace `~/` below with `C:\Users\yo - 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's `~/.local/bin/` directory automatically. 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`. +- 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 @@ -397,6 +466,10 @@ _`~/` represents the HOME directory. Please replace `~/` below with `C:\Users\yo 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. diff --git a/tmuxcc.md b/tmuxcc.md index c83646d..2298b50 100644 --- a/tmuxcc.md +++ b/tmuxcc.md @@ -4,11 +4,39 @@ layout: default # iTerm2 tmux Integration -`iTerm2` supports integration with the `tmux -CC` control mode, just add `-CC` while using `tmux` in `iTerm2`. +With `iTerm2`, you don’t need to remember the `tmux` commands and shortcuts. You can easily open new tabs and split panes, and restore everything after disconnecting and reconnecting. + +The usage is super simple, just add `-CC` while using `tmux` in `iTerm2`. - e.g., change `tmux` to `tmux -CC` - e.g., change `tmux new-session -A -s xxx` to `tmux -CC new-session -A -s xxx` +Configure the following configuration in `~/.ssh/config`. After logging in with `ssh`, all windows and programs from the last time will be automatically restored. The program will also continue to run when it is accidentally disconnected: + +``` +Host xxxxx + RequestTTY Yes + RemoteCommand tmux -u -CC new-session -A -D -X -s yyyyy /bin/bash +# You can replace the above xxxxx and yyyyy with any name you like +``` + +iTerm2 documentation: [tmux Integration](https://iterm2.com/documentation-tmux-integration.html) + +## Common Shortcuts + +The following shortcuts belongs to `iTerm2`, and works without `tmux`. + +- `command + t` open a new tab +- `command + d` split panes left and right +- `command + shift + d` split panes up and down +- `command + [` or `command + ]` switch between panes +- `command + <-` or `command + ->` switch between tabs +- `command + shift + enter` make a pane full screen or restore it +- `command + fn + <-` scroll to the front of the current output +- `command + fn + ->` scroll to the end of the current output +- `command + k` clear all the current output +- `command + control + shift + d` detach tmux, reconnecting will restore all open windows + ## Hide tmux control window By default, `iTerm2` will display two windows after running `tmux -CC`, one of them look like this: @@ -34,13 +62,6 @@ Choose your favorite way to open new window by setting `iTerm2 -> Preferences... Choose a item in `When attaching, restore windows as`, then try `tmux -CC` to find your favorite way. -## Introduction to Shortcuts - -- `command + d` Split the current pane into two, left and right. -- `command + shift + d` Split the current pane into two, top and bottom. -- `command + t` Open a new tab window. -- `command + control + shift + d` detach from tmux, run `tmux -CC attach` to attach and restore all windows. - ## Hide title bar of panes By default, `iTerm2` will show a title bar for each split panes, which looks ugly.