如何使用身份验证和SSH隧道连接到远程MongoDB

时间:2019-06-30 17:10:43

标签: mongodb shell ssh

我正在尝试使用来自ROBO3T的以下凭据连接到Remote MongoDB,并且它已成功连接。

enter image description here

enter image description here

enter image description here

我正在尝试通过.sh文件(即shell脚本)复制相同文件,并且无法正常工作。

1)这是我正在执行的frm mongo shell脚本命令,

mongo --username username --password password --authenticationDatabase admin --host ip-test --port 27017

但是我遇到了套接字异常和连接超时异常,无法连接到远程MongoDB。

2)因此,我在mongo.cfg文件中添加了以下IP,

bindIp: ip-test,127.0.0.1,0.0.0.0

3)我也在Windows Host文件中也定义了ip-test。

4)在所有配置之后,我还尝试了以下命令,

mongo -u username -p password ip-test:27017/sample --authenticationDatabase admin

但是仍然得到相同的套接字错误和连接超时。

5)然后,我尝试在mongo shell命令本身中提供ssh隧道(配置),如下所示,

mongo ip-test:27017/sample -u username -p pasword -e 'SHOW DATABASES;' -h 127.0.0.1 | ssh -fN -l root -i "path for private key/id_rsa" -L 22:ip-test:27017 ip-test

这不是给出任何套接字异常,而是给出连接超时。

当我尝试独立于终端连接ssh时,它成功。

但是问题是我想将mongo shell命令与身份验证和ssh隧道技术结合在一个命令中。

有人可以帮助我了解如何通过.SH文件(Shell脚本)通过身份验证和SSH配置连接到远程MongoDB服务器吗?

我对使用shell脚本进行ssh隧道管理非常陌生,需要帮助。

非常感谢您。

0 个答案:

没有答案