Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 使用端口转发在重新启动后连接ssh_Linux_Postgresql_Ssh_Portforwarding_Autostart - Fatal编程技术网

Linux 使用端口转发在重新启动后连接ssh

Linux 使用端口转发在重新启动后连接ssh,linux,postgresql,ssh,portforwarding,autostart,Linux,Postgresql,Ssh,Portforwarding,Autostart,我尝试在启动时使用ssh和forwading端口自动连接server->server。我需要这个,以便第一台服务器可以连接到第二台服务器的postgres DB 对于我正在使用的连接 ssh -i /root/.ssh/id_rsa -L 5434:localhost:5432 user@ipAddress 当我手动尝试时,它可以正常工作,并且我可以使用 psql -U postgres -h localhost -p 5434 将.pgpass文件放在主目录中 但问题是,ssh连接不是在启

我尝试在启动时使用ssh和forwading端口自动连接server->server。我需要这个,以便第一台服务器可以连接到第二台服务器的postgres DB

对于我正在使用的连接

ssh -i /root/.ssh/id_rsa -L 5434:localhost:5432 user@ipAddress
当我手动尝试时,它可以正常工作,并且我可以使用

psql -U postgres -h localhost -p 5434
将.pgpass文件放在主目录中

但问题是,ssh连接不是在启动时自行建立的。我曾想过使用sudo crontab的@reboot,但没有成功。。然后我尝试将脚本移动到/etc/rc.local,但也没有成功

有人能帮我在启动时建立ssh连接吗


提前感谢

我想我已经通过在ssh连接参数中添加“-N”解决了这个问题。这应该让它成为背景,而且它似乎正在发挥作用。。 所以现在我有了

ssh -N -i /root/.ssh/id_rsa -L 5434:localhost:5432 user@ipAddress
在根目录的crontab中,并在重新启动后连接。这并不能解决“冷启动”连接问题,但由于它是一台服务器,因此通常只会重新启动,而不会断电并启动