将 ssh to server 的连接写入配置文件
# 定义一个远程 server 的 ssh 连接,名称:HelloShanghai
Host HelloShanghai
# 指定 server 的域名或者 ip
HostName xxx.xxx.xxx.xxx
# 指定连接的用户名称
User root
# 指定用于连接的私钥
IdentityFile ~./ssh/private.key
# 走 nc(netcat)命令,让 ssh 通过 127.0.0.1:7890 这个 SOCKS5 本地代理,去连 %h(即 remote.host)的 %p(默认 22 端口)。
ProxyCommand nc -x 127.0.0.1:7890 %h %p
# 端口转发(例如:将server上的3306映射到本机的13306)
LocalForward 13306 127.0.0.1:3306
LocalForward 9122 127.0.0.1:22
然后在命令行中输入:ssh HelloShanghai 就可以直接连接到 server(不再需要每次 ssh root@xxx.xxx.xxx.xxx)