This page expires on 2026-11-07 21:00 Beijing time (08:00 US Eastern). After that the link stops working. Save the commands you need before then. Your ssh setup keeps working after the page is gone.
本页面在北京时间 2026-11-07 21:00(美东 08:00)失效。 之后链接不能再打开,请在这之前保存需要的命令。页面失效以后,您已经设置好的 ssh 仍然可以正常使用。
With these steps you can log in to huangrui@lang2 from your own Mac with ssh lang2, and copy files with
scp or rsync. You do not need an exit node, a VPN, or an account on the Mac mini. Setup takes about 5 minutes.
按下面的步骤设置以后,您可以在自己的 Mac 上用 ssh lang2 登录 huangrui@lang2,也可以用
scp 或 rsync 复制文件。不需要 exit node,不需要 VPN,也不需要 Mac mini 的账户。设置大约 5 分钟。
100.91.184.108:8888
→
lang2 141.211.198.52:22
The Mac mini only passes the bytes through. The ssh encryption runs directly between your Mac and lang2.
Mac mini 只负责转发数据。ssh 加密直接在您的 Mac 和 lang2 之间建立。
1Check Tailscale and Python检查 Tailscale 和 Python
Tailscale must be running and logged in on this Mac. Open Terminal and run:
这台 Mac 上的 Tailscale 必须已经打开并登录。打开"终端",运行:
tailscale ip -4 nc -vz -G 5 100.91.184.108 8888 python3 --version
- The first line prints this Mac's Tailscale address (
100.x.y.z). Only devices that Rui has allowed can use the proxy. If you use a new computer, send this address to Rui first. - 第一行显示这台 Mac 的 Tailscale 地址(
100.x.y.z)。只有 Rui 放行过的设备才能使用这个代理。如果您换了一台新电脑,请先把这个地址发给 Rui。 - The second line must say
succeeded. If it times out, Tailscale is off on this Mac, or the Mac mini is offline. - 第二行必须显示
succeeded。如果超时,说明这台 Mac 上的 Tailscale 没有打开,或者 Mac mini 不在线。 - The third line prints a Python 3 version. If macOS asks to install the command line developer tools, accept once and run it again.
- 第三行显示 Python 3 的版本。如果 macOS 提示安装命令行开发工具,请同意安装一次,然后再运行。
2Download the proxy helper下载代理脚本
ssh reaches lang2 through the Mac mini's web proxy. The small script http_connect.py (standard Python only) makes that connection, and retries by itself when the proxy drops a connection before lang2 answers. Save it in ~/.ssh/:
ssh 要经过 Mac mini 的网页代理才能连到 lang2。小脚本 http_connect.py(只用 Python 标准库)负责建立这个连接;如果代理在 lang2 回应之前断开,它会自动重试。把它保存到 ~/.ssh/:
mkdir -p ~/.ssh && chmod 700 ~/.ssh curl -fsSL https://rh-ssh-guide-17bc.pages.dev/http_connect.py -o ~/.ssh/http_connect.py shasum -a 256 ~/.ssh/http_connect.py
The last command must print c77a150b6b80e168bdb7dc8585f2dbc55fa1e6f6de40dfcb1bfbf1bce098054d. If it prints something else, do not use the file. Ask Rui.
最后一条命令必须显示 c77a150b6b80e168bdb7dc8585f2dbc55fa1e6f6de40dfcb1bfbf1bce098054d。如果显示的不一样,请不要使用这个文件,请联系 Rui。
Show the script (90 lines)查看脚本内容(90 行)
3Add lang2 to your ssh config把 lang2 加进 ssh 配置
Open ~/.ssh/config in a text editor (create it if it does not exist), for example with open -e ~/.ssh/config after touch ~/.ssh/config. Add these lines at the end:
用文本编辑器打开 ~/.ssh/config(没有就新建),例如先运行 touch ~/.ssh/config,再运行 open -e ~/.ssh/config。在文件末尾加上这几行:
Host lang2 HostName 141.211.198.52 User huangrui IdentityFile ~/.ssh/id_ed25519 IdentitiesOnly yes ServerAliveInterval 60 ProxyCommand python3 ~/.ssh/http_connect.py 100.91.184.108 8888 %h %p
IdentityFileis your private key: the one whose public key (.pub, type ed25519) you sent to Rui. If your key file has another name, change this line.IdentityFile是您的私钥,也就是您发给 Rui 的那个公钥(.pub,ed25519 类型)对应的私钥。如果您的密钥文件名不同,请改这一行。- Then run
chmod 600 ~/.ssh/config. - 然后运行
chmod 600 ~/.ssh/config。
4Log in登录
ssh lang2
The first time, ssh asks whether you trust the server. Type yes only if the fingerprint it shows is exactly:
第一次登录时,ssh 会问您是否信任这台服务器。只有当它显示的指纹和下面完全一致时,才输入 yes:
ED25519 key fingerprint is SHA256:IoYThuTmmU6ECl34h+pvHduDTCvV5izpAEz0DJW5tZ8
You should then see the lang2 prompt. Type exit to log out.
之后会看到 lang2 的命令提示符。输入 exit 退出。
5Copy files复制文件
scp and rsync use the same lang2 entry, so no extra setup is needed:
scp 和 rsync 使用同一个 lang2 配置,不需要再设置:
scp myfile.txt lang2:~/ # Mac → lang2 scp lang2:~/result.fits . # lang2 → Mac rsync -av --progress mydir/ lang2:~/mydir/ # a whole folder
Port forwarding (ssh -L, -R, -D) is turned off for this login, so tunnels such as a Jupyter port do not work.
这个登录方式关闭了端口转发(ssh -L、-R、-D),所以 Jupyter 端口之类的隧道不能用。
?If something goes wrong遇到问题时
| Message提示信息 | Meaning and what to do含义和处理办法 |
|---|---|
tunnel closed before the server spoke (try 1 of 5) |
Normal. The proxy sometimes drops a connection for a few seconds, and the script retries by itself. Nothing to do. 正常现象。代理偶尔会断开几秒钟,脚本会自动重试,不需要处理。 |
closed the tunnel 5 times before speaking |
All five tries failed. Wait one minute and run ssh lang2 again.
五次重试都失败了。等一分钟,再运行一次 ssh lang2。 |
HTTP/1.1 403 Forbidden |
The proxy does not know this computer. Send the output of tailscale ip -4 to Rui.
代理不认识这台电脑。请把 tailscale ip -4 的输出发给 Rui。 |
Connection refused / timed out |
Tailscale is off on this Mac, or the Mac mini is offline. Turn Tailscale on and repeat step 1. 这台 Mac 上的 Tailscale 没有打开,或者 Mac mini 不在线。打开 Tailscale,再做一遍第 1 步。 |
Permission denied (publickey) |
lang2 does not accept this key. Check that IdentityFile points to the private key of the public key you sent.
lang2 不接受这把密钥。请检查 IdentityFile 指向的是您发送的那个公钥对应的私钥。 |
REMOTE HOST IDENTIFICATION HAS CHANGED |
Do not continue. Contact Rui. 不要继续登录,请联系 Rui。 |
To see every step of a failing login, run ssh -v lang2 and send the last 20 lines to Rui.
想看登录失败时的每一步,可以运行 ssh -v lang2,把最后 20 行发给 Rui。