sidedoor 通过一个 shell 脚本守护进程维持 SSH 连接或隧道。
主要用途是维持到本地 SSH 服务器(或其他端口)的远程端口转发。这样,本地设备可以被访问,而无需使用可能被 NAT 或防火墙阻挡的传入连接,或对于移动设备而言不切实际的连接。
SSH 客户端可以通过 sidedoor 隧道到的反向 SSH 代理连接到设备。这个代理服务器可以由第三方或云服务运行,且不可信。
sidedoor 启用 SSH keepalives,并以指数退避重试 SSH。为了尽快重新连接,当网络接口被激活(或变更)时,它会重置退避时间。
其他用途:
你在使用 sidedoor 吗? Bug 报告、功能请求 - 请提交 issue! 欢迎提交 Pull Request。
sidedoor 为 Debian 及基于 Debian 的系统(如 Raspbian、Ubuntu 和 VyOS/EdgeOS)打包,但应该能在任何具有(OpenSSH)SSH 客户端的 POSIX 环境中工作。
如果 sidedoor 在您的发行版仓库中(Debian 9+、Ubuntu 17.04+),直接使用包管理器安装即可。
sudo apt install sidedoor
否则,您可以从 Releases 页面 手动下载 deb 包。
要授予 sidedoor 用户完整的 root 访问权限,请安装 sidedoor-sudo 包。
远程服务器和端口转发在 /etc/default/sidedoor 中配置。SSH 配置文件位于 /etc/sidedoor 目录中。
在 /etc/default/sidedoor 中配置 REMOTE_SERVER 和 OPTIONS。
关于在 OPTIONS 中传递的一些参数,请参考博文 本地和远程端口转发示例详解 和 ssh 手册页。
编辑 /etc/sidedoor 下的 SSH 配置文件。
id_rsa:访问远程服务器的 SSH 私钥。
可以使用 ssh-keygen 创建此密钥(当提示覆盖现有文件时输入 y):
sudo ssh-keygen -t rsa -N '' -f /etc/sidedoor/id_rsa
相应的公钥 id_rsa.pub 需要被包含在远程用户的 ~/.ssh/authorized_keys 文件中。
known_hosts:远程服务器的 SSH 主机密钥。
/etc/ssh/sshd_config 来锁定本地 SSH 服务器。
ChallengeResponseAuthentication no 和 PasswordAuthentication no)。ListenAddress ::1 和 ListenAddress 127.0.0.1)。sshd,例如 sudo service ssh reload。ssh_client_config_example 文件并将其包含在客户端的 ~/.ssh/config 文件中,以便轻松使用 ssh、scp、rsync 等访问隧道化的 SSH 服务器。sidedoor 旨在成为一个轻量级的端口隧道解决方案,依赖最少,但也有一些功能更丰富的替代方案。
Tor 为作为隐藏服务运行的服务器提供匿名性,同时也处理 NAT 穿透。
优点:
缺点:
在设备和客户端上都安装 Tor。
sudo apt install tor
在需要暴露的设备上,编辑 /etc/tor/torrc 以创建端口 22 的隐藏服务。
HiddenServiceDir /var/lib/tor/sshd/
HiddenServicePort 22 127.0.0.1:22
HiddenServiceAuthorizeClient stealth client
将 "client" 替换为逗号分隔的客户端名称列表,以生成多个授权密钥。
然后重新加载 Tor 并获取洋葱主机名和授权数据。
sudo service tor reload
sudo cat /var/lib/tor/sshd/hostname
在客户端,编辑 /etc/tor/torrc,添加 hostname 文件中显示的洋葱主机名和授权数据。
HidServAuth <hostname>.onion <secret>
然后重新加载 Tor 并运行 torsocks ssh <hostname>.onion,或者在 ~/.ssh/config 文件中设置 ProxyCommand。
ProxyCommand torsocks nc <hostname>.onion 22
autossh 与 sidedoor 类似,启动 ssh 并在需要时重启它。
一些不同之处包括:
sidedoor 是一个极简的 shell 脚本守护进程。 autossh 是一个更复杂且可配置的 C 程序。
sidedoor 启用 SSH keepalives(ServerAliveInterval 和 ServerAliveCountMax),这在现代版本的 OpenSSH 中可用。
autossh 通过端口转发循环发送数据来监控 ssh(此功能早于 SSH keepalives),但可以通过 -M 0 选项禁用。
sidedoor 旨在作为服务自动运行,因此软件包包含 init/systemd 脚本和配置文件。 autossh 不包含 init/systemd 脚本(Debian bug #698390)。
sidedoor 禁用远程命令和伪终端分配。对于交互式使用,请考虑使用带有 SSH keepalives 的 autossh 或 Mosh。
如果 ssh 以非零退出状态退出,sidedoor 始终重试。
autossh 在第一次尝试退出过快时不重试,这在网络连接或 DNS 解析中断时可能发生,尤其是在移动设备上。
sidedoor 和 autossh 都有重试退避逻辑。
sidedoor 在网络接口激活时重置重试退避,以尽快尝试重新连接,这是通过接收来自 if-up.d 脚本的 SIGUSR1 实现的。autossh 没有网络状态钩子。
Copyright 2015-2017 Dara Adib.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
(可选)通过将 SSH 公钥添加到文件 /etc/sidedoor/authorized_keys 来授予远程用户对本地 sidedoor 用户的访问权限。
/etc/sidedoor/authorized_keys 是指向 ~sidedoor/.ssh/authorized_keys 的符号链接。
如果安装了 sidedoor-sudo 包,则为此用户提供完整的 root 访问权限。
重新启动 sidedoor 服务以应用更改。
sudo service sidedoor restart