我必须创build一个SSH隧道来将部署服务器连接到VPN:
DeploymentServer --> Gateway --> PrivateServer
每台机器使用一个密钥,我尝试了下面的命令:
myMachine $ ssh -i GATEWAY_KEY.pem -N -L 1122:ubuntu@SERVER_PRIVATE_IP:22 ubuntu@GATEWAY_IP
然后这个在其他terminal窗口中:
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
我使用.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
然后是2个命令:
ssh -N -L 1122:SERVER_PRIVATE_IP:22 the-gateway ssh the-tunnel
这样做,SSH可以使用我的密钥。
如果我正确理解你的问题,并且你想ssh到“PrivateServer”,那么你的第二个ssh调用应该是:
myMachine $ ssh -i PRIVATE_SERVER_KEY.pem -p 1122 ubuntu@localhost
如果不是,请在您的问题的评论澄清。