Created
January 3, 2023 13:35
-
-
Save mateuszdw/dd498a57cdbdcd092dfb9f03f3d45b3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configuration for server where Postgres is hosted. | |
make sure postgres is listening on 5432 port | |
paste `id_rsa.pub` from client server to ~/.ssh/authorized_keys | |
# Configuration for client server. Where web app live and you need connect it with postgres server | |
`ssh-keygen` - to generate id_rsa.pub | |
`$ sudo apt install autossh` | |
`$ sudo nano /etc/systemd/system/autossh-tunnel.service` | |
[Unit] | |
Description=AutoSSH tunnel for postgres on port 54320 | |
After=network.target | |
[Service] | |
Environment="AUTOSSH_GATETIME=0" | |
User=user | |
Group=user | |
ExecStart=/usr/bin/autossh -M 0 -q -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -L 54320:localhost:5432 -i /home/user/.ssh/id_rsa remote-postgres@xxxxx.net | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment