Gui*_*las 4 ssh ssh-tunnel ssh-keys
我必须创建 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
Run Code Online (Sandbox Code Playgroud)
再次在第一个选项卡中:
debug1: Connection to port 1122 forwarding to ubuntu@10.0.5.128 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 ubuntu@10.0.5.128 port 22, connect from ::1 port 60341, nchannels 3
Run Code Online (Sandbox Code Playgroud)
我使用 .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
Run Code Online (Sandbox Code Playgroud)
然后是 2 个命令:
ssh -N -L 1122:SERVER_PRIVATE_IP:22 the-gateway
ssh the-tunnel
Run Code Online (Sandbox Code Playgroud)
这样,SSH 就可以使用我的 pem 密钥。