5 个版本
0.1.5 | 2024年3月23日 |
---|---|
0.1.4 | 2024年3月23日 |
0.1.3 | 2024年3月23日 |
0.1.2 | 2024年3月23日 |
0.1.1 | 2024年3月23日 |
#586 在 开发工具
45KB
1K SLoC
稳定的SSH
即使笔记本电脑关闭,网络切换或通信不稳定,也能保持SSH连接
功能
- 在WiFi/优先之间切换无缝。
- 抵抗长时间的通信中断。(例如,客户端终端休眠)
- 使用quic封装SSH以增加稳定性。
- 内部缓冲区可以重试和重新传输连接。
类似软件
受到以下软件的影响,但在某些方面有所不同。
- quicssh-rs
- 将SSH封装在quic中的点相同。
- 由于quicssh-rs没有内部缓冲区或重试功能,没有长时间通信中断的机制(例如,客户端休眠)。
- mosh
- 保留了相同的内部缓冲区和重试功能,使其能够容忍长时间的通信中断。
- 它不是ssh,因此没有端口转发、文件传输、vscode远程等功能。
使用方法
安装
对于Mac(homebrew)
brew install hrntknr/tap/stablessh
对于其他平台
cargo install stablessh
客户端配置 (sshconfig)
Host target
Port 2222
ProxyCommand stablessh client %h:%p
VSCode配置(远程ssh)
"remote.SSH.useLocalServer": false,
服务器守护进程(systemd)
[Unit]
Description=stablessh Daemon
[Service]
Type=simple
ExecStart=/usr/local/bin/stablessh server
[Install]
WantedBy=multi-user.target
控制命令
> $ stablessh ctl conn list
id | name | last_active | pkt_buf
----------+------+-------------+---------
d01c1bbe | mba | in_use | 0
aba69f2a | mba | 6 | 0
> $ stablessh ctl conn kill aba69f2a
> $ stablessh ctl conn list
id | name | last_active | pkt_buf
----------+------+-------------+---------
d01c1bbe | mba | in_use | 0
选项
> $ stablessh --help
Usage: stablessh <COMMAND>
Commands:
server
client
ctl
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
> $ stablessh client --help
Usage: stablessh client [OPTIONS] <TARGET>
Arguments:
<TARGET>
Options:
-i, --idle <IDLE> [default: 3]
-k, --keepalive <KEEPALIVE> [default: 1]
-b, --bufsize <BUFSIZE> [default: 32]
-4, --only-ipv4
-6, --only-ipv6
-h, --help Print help
> $ stablessh server --help
Usage: stablessh server [OPTIONS]
Options:
-i, --idle <IDLE> [default: 3]
-k, --keepalive <KEEPALIVE> [default: 1]
-b, --bufsize <BUFSIZE> [default: 18]
-t, --hold-timeout <HOLD_TIMEOUT> [default: 604800]
-c, --hold-collect-interval <HOLD_COLLECT_INTERVAL> [default: 60]
-l, --listen <LISTEN> [default: 0.0.0.0:2222]
-f, --forward <FORWARD> [default: localhost:22]
-h, --help Print help
性能
StableSSH的主要目标是便利性而不是性能。
然而,在轻度测量中,性能约为ssh的50%。
> $ scp ~/100m stablessh:
100m 100% 100MB 5.4MB/s 00:18
> $ scp ~/100m ssh:
100m 100% 100MB 11.3MB/s 00:08
关于bufsize
bufsize指定缓冲区的大小(上限32)
默认值允许缓冲区有32位空间,但它可能会消耗无限内存。
如果担心内存使用,请尝试减小bufsize。
(最大内存大小) = 4096 * 2 ^ (bufsize) [字节]
bufsize | 最大内存 |
---|---|
4 | 64K |
8 | 1M |
16 | 256M |
18 | 1G |
20 | 4G |
22 | 16G |
24 | 64G |
32 | 16T |
依赖项
~20–31MB
~544K SLoC