Differences between revisions 21 and 40 (spanning 19 versions)
Size: 9120
Comment:
|
Size: 9728
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 5: | Line 5: |
/* College VPN does not work since /etc/postgresql/8.3/db/pg_hba.conf only allows 146.169.0.0 | |
Line 8: | Line 8: |
*/ | |
Line 10: | Line 11: |
This is similar to using VPN but at an application-level. Use an SSH client to create a tunnel from your computer outside the network to db.doc.ic.ac.uk through one of the externally-accessible SSH servers: shell1.doc.ic.ac.uk -- shell4.doc.ic.ac.uk. Here is the syntax from a Linux terminal (the same command can be run in a Mac OS X terminal): | Use an SSH client to create a tunnel from your computer outside the college network to db.doc.ic.ac.uk through one of the externally-accessible SSH servers: shell1.doc.ic.ac.uk - shell4.doc.ic.ac.uk. Here is the syntax from a Linux terminal (the same command can be run in a Mac OS X terminal): |
Line 14: | Line 15: |
After you authenticate, the above command will set up a tunnel from port 12345 on your local computer to port 5432 (upon which the PostgreSQL service listens on db.doc.ic.ac.uk). You can then configure the PostgreSQL client on your local computer to | After you authenticate, the above command will set up a tunnel from port 12345 on your local computer to port 5432 (upon which the PostgreSQL service listens) on db.doc.ic.ac.uk. You can then configure the PostgreSQL client on your local computer to |
Line 17: | Line 18: |
{{{psql --host localhost --port 12345 -U postgreUserName --dbname=postgresDatabaseName}}} | {{{psql --host localhost --port 12345 --username pgUser --dbname theDB}}} |
Line 19: | Line 20: |
This assumes that the PostgreSQL client 'psql' is installed locally. You can use [[http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html|plink]] under Windows to run the same SSH port-forwarding (plink documentation [[http://the.earth.li/~sgtatham/putty/0.58/htmldoc/Chapter7.html|here]]). | (Replace {{{pguser}}} and {{{theDB}}} with the appropriate DoC PostgreSQL user-name and database respectively). The above {{{psql}}} command assumes that the PostgreSQL command-line client application of that name is installed locally. You can use [[http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html|plink]] under Windows to run the same SSH port-forwarding (plink documentation [[http://the.earth.li/~sgtatham/putty/0.58/htmldoc/Chapter7.html|here]]). |
Line 24: | Line 27: |
Suppose that you want to (or must use) SSL encryption but you do not care about validating the SSL certificate for db.doc.ic.ac.uk. First of all, you will need the PostgreSQL jdbc driver in your Java classpath. Download the JAR file from http://jdbc.postgresql.org/ or if you are using Debian or Ubuntu, 'apt-get install libpg-java' (which installs /usr/share/java/postgresql.jar). Update your CLASSPATH environment variable to reference the relevant JAR file location or include it in the '-cp' argument of your java/javac invocations. |
Suppose that you want to (or must) use SSL encryption but you do not care about validating the SSL certificate for db.doc.ic.ac.uk. First of all, you will need the PostgreSQL jdbc driver in your Java classpath. Download the JAR file from http://jdbc.postgresql.org/ or if you are using Debian or Ubuntu, '{{{apt-get install libpg-java}}}' (which installs /usr/share/java/postgresql.jar). Update your CLASSPATH environment variable to reference the relevant JAR file location or include it in the '-cp' argument of your java/javac invocations. |
Line 29: | Line 32: |
{{{jdbc:postgresql://db.doc.ic.ac.uk/theDB?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory}}} | {{{ jdbc:postgresql://db.doc.ic.ac.uk/theDB?ssl=true& sslfactory=org.postgresql.ssl.NonValidatingFactory }}} (That is one line: it has been line-wrapped above so that it is fully displayed). |
Line 72: | Line 79: |
Change the obvious strings ({{{pgUser}}} and {{{pgUserPassword}}}), save it under the file-name {{{'CheckDoCDB1.java'}}} and compile it like so (we assume that you are using Debian/Ubuntu; adjust JAR file location as required): | Change the obvious strings ({{{theDB}}}, {{{pgUser}}} and {{{pgUserPassword}}}), save it under the file-name {{{'CheckDoCDB1.java'}}} and compile it like so (we assume that you are using Debian/Ubuntu; adjust JAR file location as required): |
Line 141: | Line 148: |
"authenticated SSL."); | "SSL with validation."); |
Line 151: | Line 158: |
As before, change the strings ({{{pgUser}}} and {{{pgUserPassword}}}). You should also adjust ''/home/userName/.keystore'' to refer to the local path of the created key store and ''keystorePassword'' to be the password string that you specified for the key store. Save the above code under the file-name {{{'CheckDoCDB2.java'}}} and compile it like so: | As before, change the parameters as required ({{{theDB}}}, {{{pgUser}}} and {{{pgUserPassword}}}). You should also adjust ''/home/userName/.keystore'' to refer to the local path of the created key store and ''keystorePassword'' to be the password string that you specified for the key store. Save the above code under the file-name {{{'CheckDoCDB2.java'}}} and compile it like so: |
Line 164: | Line 171: |
* Are you referencing the PostgreSQL jdbc driver correctly in your Java classpath? * Did you correctly configure and reference a local Java key store? |
|
Line 168: | Line 177: |
You can use the command {{{psql -h db.doc.ic.ac.uk -d theDB -U pgUser}}} on a DoC Linux computer to | Remember that you can use the command {{{psql --host db.doc.ic.ac.uk --username pgUser --dbname theDB}}} on a DoC Linux computer to |
Line 172: | Line 181: |
Please see [[http://jdbc.postgresql.org/documentation/83/ssl-client.html|the JDBC documentation]] for more details. | Please see the [[http://developer.postgresql.org/pgdocs/postgres/ssh-tunnels.html|PostgreSQL]] and [[http://jdbc.postgresql.org/documentation/83/ssl-client.html|JDBC]] documentation for more details. |
PostgreSQL connections from off-site
If you want to connect directly to the PostgreSQL server from outside the college network, you must use SSL encryption. Here are four possible ways to address this.