~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to doc/src/sgml/html/ssh-tunnels.html

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
2
<HTML
 
3
><HEAD
 
4
><TITLE
 
5
>Secure TCP/IP Connections with SSH Tunnels</TITLE
 
6
><META
 
7
NAME="GENERATOR"
 
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
 
9
REV="MADE"
 
10
HREF="mailto:pgsql-docs@postgresql.org"><LINK
 
11
REL="HOME"
 
12
TITLE="PostgreSQL 9.1beta1 Documentation"
 
13
HREF="index.html"><LINK
 
14
REL="UP"
 
15
TITLE="Server Setup and Operation"
 
16
HREF="runtime.html"><LINK
 
17
REL="PREVIOUS"
 
18
TITLE="Secure TCP/IP Connections with SSL"
 
19
HREF="ssl-tcp.html"><LINK
 
20
REL="NEXT"
 
21
TITLE="Server Configuration"
 
22
HREF="runtime-config.html"><LINK
 
23
REL="STYLESHEET"
 
24
TYPE="text/css"
 
25
HREF="stylesheet.css"><META
 
26
HTTP-EQUIV="Content-Type"
 
27
CONTENT="text/html; charset=ISO-8859-1"><META
 
28
NAME="creation"
 
29
CONTENT="2011-04-27T21:20:33"></HEAD
 
30
><BODY
 
31
CLASS="SECT1"
 
32
><DIV
 
33
CLASS="NAVHEADER"
 
34
><TABLE
 
35
SUMMARY="Header navigation table"
 
36
WIDTH="100%"
 
37
BORDER="0"
 
38
CELLPADDING="0"
 
39
CELLSPACING="0"
 
40
><TR
 
41
><TH
 
42
COLSPAN="5"
 
43
ALIGN="center"
 
44
VALIGN="bottom"
 
45
><A
 
46
HREF="index.html"
 
47
>PostgreSQL 9.1beta1 Documentation</A
 
48
></TH
 
49
></TR
 
50
><TR
 
51
><TD
 
52
WIDTH="10%"
 
53
ALIGN="left"
 
54
VALIGN="top"
 
55
><A
 
56
TITLE="Secure TCP/IP Connections with SSL"
 
57
HREF="ssl-tcp.html"
 
58
ACCESSKEY="P"
 
59
>Prev</A
 
60
></TD
 
61
><TD
 
62
WIDTH="10%"
 
63
ALIGN="left"
 
64
VALIGN="top"
 
65
><A
 
66
TITLE="Server Setup and Operation"
 
67
HREF="runtime.html"
 
68
>Fast Backward</A
 
69
></TD
 
70
><TD
 
71
WIDTH="60%"
 
72
ALIGN="center"
 
73
VALIGN="bottom"
 
74
>Chapter 17. Server Setup and Operation</TD
 
75
><TD
 
76
WIDTH="10%"
 
77
ALIGN="right"
 
78
VALIGN="top"
 
79
><A
 
80
TITLE="Server Setup and Operation"
 
81
HREF="runtime.html"
 
82
>Fast Forward</A
 
83
></TD
 
84
><TD
 
85
WIDTH="10%"
 
86
ALIGN="right"
 
87
VALIGN="top"
 
88
><A
 
89
TITLE="Server Configuration"
 
90
HREF="runtime-config.html"
 
91
ACCESSKEY="N"
 
92
>Next</A
 
93
></TD
 
94
></TR
 
95
></TABLE
 
96
><HR
 
97
ALIGN="LEFT"
 
98
WIDTH="100%"></DIV
 
99
><DIV
 
100
CLASS="SECT1"
 
101
><H1
 
102
CLASS="SECT1"
 
103
><A
 
104
NAME="SSH-TUNNELS"
 
105
>17.10. Secure TCP/IP Connections with <SPAN
 
106
CLASS="APPLICATION"
 
107
>SSH</SPAN
 
108
> Tunnels</A
 
109
></H1
 
110
><P
 
111
>   It is possible to use <SPAN
 
112
CLASS="APPLICATION"
 
113
>SSH</SPAN
 
114
> to encrypt the network
 
115
   connection between clients and a
 
116
   <SPAN
 
117
CLASS="PRODUCTNAME"
 
118
>PostgreSQL</SPAN
 
119
> server. Done properly, this
 
120
   provides an adequately secure network connection, even for non-SSL-capable
 
121
   clients.
 
122
  </P
 
123
><P
 
124
>   First make sure that an <SPAN
 
125
CLASS="APPLICATION"
 
126
>SSH</SPAN
 
127
> server is
 
128
   running properly on the same machine as the
 
129
   <SPAN
 
130
CLASS="PRODUCTNAME"
 
131
>PostgreSQL</SPAN
 
132
> server and that you can log in using
 
133
   <TT
 
134
CLASS="COMMAND"
 
135
>ssh</TT
 
136
> as some user. Then you can establish a secure
 
137
   tunnel with a command like this from the client machine:
 
138
</P><PRE
 
139
CLASS="PROGRAMLISTING"
 
140
>ssh -L 63333:localhost:5432 joe@foo.com</PRE
 
141
><P>
 
142
   The first number in the <TT
 
143
CLASS="OPTION"
 
144
>-L</TT
 
145
> argument, 63333, is the
 
146
   port number of your end of the tunnel; it can be any unused port.
 
147
   (IANA reserves ports 49152 through 65535 for private use.)  The
 
148
   second number, 5432, is the remote end of the tunnel: the port
 
149
   number your server is using. The name or IP address between the
 
150
   port numbers is the host with the database server you are going to
 
151
   connect to, as seen from the host you are logging in to, which
 
152
   is <TT
 
153
CLASS="LITERAL"
 
154
>foo.com</TT
 
155
> in this example. In order to connect
 
156
   to the database server using this tunnel, you connect to port 63333
 
157
   on the local machine:
 
158
</P><PRE
 
159
CLASS="PROGRAMLISTING"
 
160
>psql -h localhost -p 63333 postgres</PRE
 
161
><P>
 
162
   To the database server it will then look as though you are really
 
163
   user <TT
 
164
CLASS="LITERAL"
 
165
>joe</TT
 
166
> on host <TT
 
167
CLASS="LITERAL"
 
168
>foo.com</TT
 
169
>
 
170
   connecting to <TT
 
171
CLASS="LITERAL"
 
172
>localhost</TT
 
173
> in that context, and it
 
174
   will use whatever authentication procedure was configured for
 
175
   connections from this user and host.  Note that the server will not
 
176
   think the connection is SSL-encrypted, since in fact it is not
 
177
   encrypted between the
 
178
   <SPAN
 
179
CLASS="APPLICATION"
 
180
>SSH</SPAN
 
181
> server and the
 
182
   <SPAN
 
183
CLASS="PRODUCTNAME"
 
184
>PostgreSQL</SPAN
 
185
> server.  This should not pose any
 
186
   extra security risk as long as they are on the same machine.
 
187
  </P
 
188
><P
 
189
>   In order for the
 
190
   tunnel setup to succeed you must be allowed to connect via
 
191
   <TT
 
192
CLASS="COMMAND"
 
193
>ssh</TT
 
194
> as <TT
 
195
CLASS="LITERAL"
 
196
>joe@foo.com</TT
 
197
>, just
 
198
   as if you had attempted to use <TT
 
199
CLASS="COMMAND"
 
200
>ssh</TT
 
201
> to create a
 
202
   terminal session.
 
203
  </P
 
204
><P
 
205
>   You could also have set up the port forwarding as
 
206
</P><PRE
 
207
CLASS="PROGRAMLISTING"
 
208
>ssh -L 63333:foo.com:5432 joe@foo.com</PRE
 
209
><P>
 
210
   but then the database server will see the connection as coming in
 
211
   on its <TT
 
212
CLASS="LITERAL"
 
213
>foo.com</TT
 
214
> interface, which is not opened by
 
215
   the default setting <TT
 
216
CLASS="LITERAL"
 
217
>listen_addresses =
 
218
   'localhost'</TT
 
219
>.  This is usually not what you want.
 
220
  </P
 
221
><P
 
222
>   If you have to <SPAN
 
223
CLASS="QUOTE"
 
224
>"hop"</SPAN
 
225
> to the database server via some
 
226
   login host, one possible setup could look like this:
 
227
</P><PRE
 
228
CLASS="PROGRAMLISTING"
 
229
>ssh -L 63333:db.foo.com:5432 joe@shell.foo.com</PRE
 
230
><P>
 
231
   Note that this way the connection
 
232
   from <TT
 
233
CLASS="LITERAL"
 
234
>shell.foo.com</TT
 
235
>
 
236
   to <TT
 
237
CLASS="LITERAL"
 
238
>db.foo.com</TT
 
239
> will not be encrypted by the SSH
 
240
   tunnel.
 
241
   SSH offers quite a few configuration possibilities when the network
 
242
   is restricted in various ways.  Please refer to the SSH
 
243
   documentation for details.
 
244
  </P
 
245
><DIV
 
246
CLASS="TIP"
 
247
><BLOCKQUOTE
 
248
CLASS="TIP"
 
249
><P
 
250
><B
 
251
>Tip: </B
 
252
>    Several other applications exist that can provide secure tunnels using
 
253
    a procedure similar in concept to the one just described.
 
254
   </P
 
255
></BLOCKQUOTE
 
256
></DIV
 
257
></DIV
 
258
><DIV
 
259
CLASS="NAVFOOTER"
 
260
><HR
 
261
ALIGN="LEFT"
 
262
WIDTH="100%"><TABLE
 
263
SUMMARY="Footer navigation table"
 
264
WIDTH="100%"
 
265
BORDER="0"
 
266
CELLPADDING="0"
 
267
CELLSPACING="0"
 
268
><TR
 
269
><TD
 
270
WIDTH="33%"
 
271
ALIGN="left"
 
272
VALIGN="top"
 
273
><A
 
274
HREF="ssl-tcp.html"
 
275
ACCESSKEY="P"
 
276
>Prev</A
 
277
></TD
 
278
><TD
 
279
WIDTH="34%"
 
280
ALIGN="center"
 
281
VALIGN="top"
 
282
><A
 
283
HREF="index.html"
 
284
ACCESSKEY="H"
 
285
>Home</A
 
286
></TD
 
287
><TD
 
288
WIDTH="33%"
 
289
ALIGN="right"
 
290
VALIGN="top"
 
291
><A
 
292
HREF="runtime-config.html"
 
293
ACCESSKEY="N"
 
294
>Next</A
 
295
></TD
 
296
></TR
 
297
><TR
 
298
><TD
 
299
WIDTH="33%"
 
300
ALIGN="left"
 
301
VALIGN="top"
 
302
>Secure TCP/IP Connections with SSL</TD
 
303
><TD
 
304
WIDTH="34%"
 
305
ALIGN="center"
 
306
VALIGN="top"
 
307
><A
 
308
HREF="runtime.html"
 
309
ACCESSKEY="U"
 
310
>Up</A
 
311
></TD
 
312
><TD
 
313
WIDTH="33%"
 
314
ALIGN="right"
 
315
VALIGN="top"
 
316
>Server Configuration</TD
 
317
></TR
 
318
></TABLE
 
319
></DIV
 
320
></BODY
 
321
></HTML
 
322
>
 
 
b'\\ No newline at end of file'