ZeroTier + SSH 远程连接 WSL2 子系统

ZeroTier + SSH 远程连接 WSL2 子系统
空空Voemp使用 ZeroTier One 进行组网
- 将桌面客户端更新到最新版本
- 使用路由器的 ZeroTier 插件,在 ZeroTier控制台里将路由器设置为 Routes
WSL 内配置
- 安装配置 ssh 服务
1
2
3
4
5
6# 重新安装一遍 ssh
sudo apt remove openssh-server
sudo apt install openssh-server
# 不需要改配置文件了
# sudo vim /etc/ssh/sshd_config - WSL 网络模式为 NAT 模式
Windows 内配置
- 配置端口转发
防止 WSL2 的 localhost 转发不稳定,所以使用
v4tov6
1
netsh interface portproxy add v4tov6 listenaddress=0.0.0.0 listenport=2222 connectaddress=::1 connectport=22
- 配置防火墙入站规则
1
netsh advfirewall firewall add rule name=WSL2 dir=in action=allow protocol=TCP localport=2222
- 本地连接
1
ssh <username>@::1
- 远程主机连接
1
ssh <username>@<远程主机在 ZeroTier 中被分配的 IP> -p 2222
无须密码 SSH 连接
- 先在远程主机上生成密钥
1
ssh-keygen
- WSL 内记录公钥
1
2
3
4
5
6
7# mkdir ~/.ssh
cd ~/.ssh
# 将公钥复制到需要连接的 WSL 用户目录的 `~/.ssh` 下
# 再执行
cat id_rsa.pub >> authorized_keys - 之后连接就不需要输入密码了
评论
匿名评论隐私政策
✅ 你无需删除空行,直接评论以获取最佳展示效果