클라이언트와 PostgreSQL 서버 간 네트워크 연결을 암호화하기 위해 SSH를 사용할 수 있다. 제대로 된 경우 이것은 SSL이 불가능한 클라이언트에 대해서도 적절한 네트워크 연결 보호를 제공한다.
먼저 SSH 서버가 PostgreSQL 서버와
동일한 머신에서 올바로 실행 중인지 확인하고 ssh
를 사용하여
일부 사용자로 로그인할 수 있는지 확인한다. you then can establish a
secure tunnel to the remote server. A secure tunnel listens on a
local port and forwards all traffic to a port on the remote machine.
Traffic sent to the remote port can arrive on its
localhost
address, or different bind
address if desired; it does not appear as coming from your
local machine. This command creates a secure tunnel from the client
machine to the remote machine foo.com
:
ssh -L 63333:localhost:5432 joe@foo.com
-L
의 첫 번째 인수 63333은 터널 종단의
로컬 포트 번호이며, 미사용 포트는 무엇이든 가능하다.
(IANA는 개인용으로 포트 49152 ~ 65535를 제공한다.)
The name or IP
address after this is the remote bind address you are connecting to,
i.e., localhost
, which is the default. The second
number, 5432, is the remote end of the tunnel, e.g., the port number
your database server is using.
이 터널을 사용하여 데이터베이스 서버에 연결하기 위해 사용자는 로컬 머신의 포트 63333에 연결한다.
psql -h localhost -p 63333 postgres
To the database server it will then look as though you are
user joe
on host foo.com
connecting to the localhost
bind address, and it
will use whatever authentication procedure was configured for
connections by that user to that bind address. Note that the server will not
think the connection is SSL-encrypted, since in fact it is not
encrypted between the
SSH server and the
PostgreSQL server. This should not pose any
extra security risk because they are on the same machine.
터널 설정이 성공하려면 사용자가 ssh
를 사용하여 터미널 세션을 생성하려고 하는 것처럼 joe@foo.com
로써 ssh
를 통한 연결이 허용되어야 한다
사용자는 다음과 같이 포트 포워딩을 설정할 수도 있다.
ssh -L 63333:foo.com:5432 joe@foo.com
그러나 데이터베이스 서버가 foo.com
바인드 주소에서 들어오는 연결을 보게 되는데, 이것은 기본 설정 listen_addresses =
'localhost'
에 의해서는 개방되지 않는다. 보통 이것은 사용자가 원하는 바가 아니다.
일부 로그인 호스트를 통해 데이터베이스 서버에 “hop”해야 한다면 가능한 설정 중 하나는 다음과 같을 것이다.
ssh -L 63333:db.foo.com:5432 joe@shell.foo.com
shell.foo.com
에서 db.foo.com
으로의 이러한 연결 방법은 SSH 터널에서 암호화되지 않는다는 점에 유의해야 한다. 다양한 방법으로 네트워크가 제한되는 경우에 SSH는 가능한 환경 설정을 다수 제공한다. 자세한 내용은 SSH 문서를 참조 바란다.
방금 설명한 개념과 유사한 절차를 사용하여 보안 터널을 제공할 수 있는 몇 가지 다른 어플리케이션이 존재한다.