我在跑:
ssh -N -R 2222:localhost:22 phil@myserver.com
Run Code Online (Sandbox Code Playgroud)
这是有效的,但我想保持这个连接打开,这样我就可以随时访问我的 pi。当我等待一两天后尝试时,我无法连接。当我检查 pi 上的 tmux 会话时,它说:
写入失败:管道损坏
如何设置脚本以自动重新连接?
小智 5
对于现在正在寻找此服务的人,我发现 systemd 服务比 autossh(运行 Debian 10.4)更可靠。就我而言,autossh 经常在几天后失败,systemd 解决方案运行数周/数月没有问题。
/etc/systemd/system/ssh_remote_access.service 的内容:
[Unit]
Description=SSH reverse tunnel
After=network.target
[Service]
User=PUT_YOUR_LINUX_USER_NAME_HERE
Restart=always
RestartSec=20
ExecStart=/usr/bin/ssh -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -o "ExitOnForwardFailure yes" -N -R 2222:localhost:22 phil@myserver.com
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
然后激活服务:
sudo systemctl daemon-reload
sudo systemctl enable ssh_remote_access
sudo systemctl start ssh_remote_access
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2837 次 |
最近记录: |