LoginSignup
11
13

More than 5 years have passed since last update.

SSHトンネルでPostgreSQLに接続

Posted at

SSHトンネルを使う

参考URL

SSH例

ssh -L 12000:localhost:5432 hoge@example.com

Windowsの場合、Putty設定>接続>SSH>トンネル

  • 源ポート:空いている適当なポート(例:12000)
  • 送り先:localhost:5432

追加ボタンを押し忘れないようにする。
接続する前に設定を保存しておくと便利。

SSH接続してログインする。
サーバーの設定はデフォルトではNGなので、例えば次のように設定する。

サーバーの設定例

postgresql.confの修正

次をアンコメントする。

postgresql.conf
listen_addresses = 'localhost'

pg_hba.confの修正

pg_hba.conf
# "local" is for Unix domain socket connections only
local   all         all                               ident
# IPv4 local connections:
host    all         all         127.0.0.1/32          password
# IPv6 local connections:
host    all         all         ::1/128               password

こんな感じにする。

※サーバーに接続する人がただ一人だけなら、passwordの代わりにtrustを設定すると便利。
trustを設定する注意点についてはこちらに記載されていました。
http://www.postgresql.jp/document/9.3/html/auth-methods.html#AUTH-TRUST

設定を反映

service postgresql reload
11
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
13