Skip to content

Commit f1b2b11

Browse files
committed
doc: clarify the use of ssh port forwarding
Reported-by: karimelghazouly@gmail.com Discussion: https://postgr.es/m/159854511172.24991.4373145230066586863@wrigleys.postgresql.org Backpatch-through: 9.5
1 parent 4857e6f commit f1b2b11

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

doc/src/sgml/runtime.sgml

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,34 +2476,39 @@ openssl x509 -req -in server.csr -text -days 365 \
24762476
First make sure that an <application>SSH</application> server is
24772477
running properly on the same machine as the
24782478
<productname>PostgreSQL</productname> server and that you can log in using
2479-
<command>ssh</command> as some user. Then you can establish a secure
2480-
tunnel with a command like this from the client machine:
2479+
<command>ssh</command> as some user; you then can establish a
2480+
secure tunnel to the remote server. A secure tunnel listens on a
2481+
local port and forwards all traffic to a port on the remote machine.
2482+
Traffic sent to the remote port can arrive on its
2483+
<literal>localhost</literal> address, or different bind
2484+
address if desired; it does not appear as coming from your
2485+
local machine. This command creates a secure tunnel from the client
2486+
machine to the remote machine <literal>foo.com</literal>:
24812487
<programlisting>
24822488
ssh -L 63333:localhost:5432 joe@foo.com
24832489
</programlisting>
24842490
The first number in the <option>-L</option> argument, 63333, is the
2485-
port number of your end of the tunnel; it can be any unused port.
2486-
(IANA reserves ports 49152 through 65535 for private use.) The
2487-
second number, 5432, is the remote end of the tunnel: the port
2488-
number your server is using. The name or IP address between the
2489-
port numbers is the host with the database server you are going to
2490-
connect to, as seen from the host you are logging in to, which
2491-
is <literal>foo.com</literal> in this example. In order to connect
2492-
to the database server using this tunnel, you connect to port 63333
2493-
on the local machine:
2491+
local port number of the tunnel; it can be any unused port. (IANA
2492+
reserves ports 49152 through 65535 for private use.) The name or IP
2493+
address after this is the remote bind address you are connecting to,
2494+
i.e., <literal>localhost</literal>, which is the default. The second
2495+
number, 5432, is the remote end of the tunnel, e.g., the port number
2496+
your database server is using. In order to connect to the database
2497+
server using this tunnel, you connect to port 63333 on the local
2498+
machine:
24942499
<programlisting>
24952500
psql -h localhost -p 63333 postgres
24962501
</programlisting>
2497-
To the database server it will then look as though you are really
2502+
To the database server it will then look as though you are
24982503
user <literal>joe</literal> on host <literal>foo.com</literal>
2499-
connecting to <literal>localhost</literal> in that context, and it
2504+
connecting to the <literal>localhost</literal> bind address, and it
25002505
will use whatever authentication procedure was configured for
2501-
connections from this user and host. Note that the server will not
2506+
connections by that user to that bind address. Note that the server will not
25022507
think the connection is SSL-encrypted, since in fact it is not
25032508
encrypted between the
25042509
<application>SSH</application> server and the
25052510
<productname>PostgreSQL</productname> server. This should not pose any
2506-
extra security risk as long as they are on the same machine.
2511+
extra security risk because they are on the same machine.
25072512
</para>
25082513

25092514
<para>
@@ -2515,12 +2520,12 @@ psql -h localhost -p 63333 postgres
25152520
</para>
25162521

25172522
<para>
2518-
You could also have set up the port forwarding as
2523+
You could also have set up port forwarding as
25192524
<programlisting>
25202525
ssh -L 63333:foo.com:5432 joe@foo.com
25212526
</programlisting>
25222527
but then the database server will see the connection as coming in
2523-
on its <literal>foo.com</literal> interface, which is not opened by
2528+
on its <literal>foo.com</literal> bind address, which is not opened by
25242529
the default setting <literal>listen_addresses =
25252530
'localhost'</literal>. This is usually not what you want.
25262531
</para>

0 commit comments

Comments
 (0)