我在 AWS 上有数据库服务器,在下面的场景中,我必须使用 ssh 隧道从我的 PC 访问该数据库。
PC --> Jump1 [x.pem, port:22] --> Jump2 [y.pem, port:443] --> mysqldb:3306
最佳答案
对于这种场景,配置文件是最好的方法。
运行
$ touch ~/.ssh/config
在配置文件中添加主机条目。
Host <Host_Name>
HostName <URL/IP of Jump2>
User <>
Port <>
Identityfile <yyy.pem>
StrictHostKeyChecking no
ProxyCommand ssh -i <xxx.pem> <user>@<IP/DNS of Jump1> nc %h %p 2> /dev/null
然后创建隧道
$ ssh <local_port>:DB_URL:<DB PORT> <Host_name>
就是这样。 现在您可以使用
连接到数据库localhost:<local_port>
关于使用不同 key 从两级跳转服务器到数据库的 SSH 隧道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39102873/