Skip to content

Instantly share code, notes, and snippets.

@mateuszdw
Created January 3, 2023 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mateuszdw/dd498a57cdbdcd092dfb9f03f3d45b3a to your computer and use it in GitHub Desktop.
Save mateuszdw/dd498a57cdbdcd092dfb9f03f3d45b3a to your computer and use it in GitHub Desktop.
# 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