我必须创建一个 SSH 隧道来将部署服务器连接到 VPN:
DeploymentServer --> Gateway --> PrivateServer
每台机器使用一个密钥,我尝试了以下命令:
myMachine $ ssh -i GATEWAY_KEY.pem -N -L 1122:ubuntu@SERVER_PRIVATE_IP:22 ubuntu@GATEWAY_IP
然后在另一个终端窗口中运行这个:
myMachine $ ssh -i PRIVATE_SERVER_KEY.pem -p 1122 ubuntu@SERVER_PRIVATE_IP
但它不起作用,我收到超时错误。我的端口 1122 已打开,我可以通过 SSH 连接它。我不知道我做错了什么,我的语法正确吗?
这是我的第一条隧道,所以不要嘲笑我!
编辑1
我添加-v
并修复了第二个 SSH 调用。
第一次呼叫:
myMachine $ ssh -i GATEWAY_KEY.pem -N -L 1122:ubuntu@SERVER_PRIVATE_IP:22 ubuntu@GATEWAY_IP -v
响应:debug1: Authentication succeeded (publickey).
第二次呼叫:
myMachine $ ssh -i PRIVATE_SERVER_KEY.pem -p 1122 ubuntu@localhost -v
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to localhost [::1] port 1122.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file .ssh/wamapi_staging.pem type -1
debug1: identity file .ssh/wamapi_staging.pem-cert type -1
ssh_exchange_identification: Connection closed by remote host
在第一个标签中:
debug1: Connection to port 1122 forwarding to [email protected] port 22 requested.
debug1: channel 2: new [direct-tcpip]
channel 2: open failed: administratively prohibited: open failed
debug1: channel 2: free: direct-tcpip: listening port 1122 for [email protected] port 22, connect from ::1 port 60341, nchannels 3
答案1
我使用 .ssh/config 文件来让它工作,而不是尝试将所有参数都放在命令中。如果有人需要,以下是结果:
Host the-gateway
Hostname GATEWAY_IP
Port 22
User ubuntu
IdentityFile ~/.ssh/keys/GATEWAY_KEY.pem
Host the-tunnel
Hostname localhost
Port 1122
User ubuntu
IdentityFile ~/.ssh/keys/PRIVATE_SERVER_KEY.pem
然后是两个命令:
ssh -N -L 1122:SERVER_PRIVATE_IP:22 the-gateway
ssh the-tunnel
这样一来,SSH 就可以使用我的 pem 密钥了。
答案2
如果我正确理解了你的问题,并且你想要 ssh 到“PrivateServer”,那么你的第二个 ssh 调用应该是:
myMachine $ ssh -i PRIVATE_SERVER_KEY.pem -p 1122 ubuntu@localhost
如果没有,请在问题的评论中澄清。