Mount a SFTP connection to a folder in Ubuntu / Linux

To do this I used a program called SSHFS which has done a great job. First, install if from the repo

sudo apt-get install sshfs

You’ll need to create a directory to use as the location for your files

sudo mkdir /mnt/sshftps

Execute the command to connect the actual SFTP Server. Replace xxx.xxx with the target IP address and use the -p option to specify the connection port. The user parameter is your user name. The :/ at the end of the IP address indicates the end of the IP address. Don’t try to put the port number after the colon

sudo sshfs -o allow_other -p 6789 user@xxx.xx.xxx.xx:/ /mnt/sshftps

This will create a semi-permanent connection which will close if the machine is restarted. You can create a permanent connection which will reopen when the machine starts by editing the fstab file in /etc/fstab. Add a command to the end and restart the machine. Personally, I haven’t tried this because it’s a potential security risk and I didn’t need 100% uptime.

sshfs#username@xxx.xxx.xxx.xxx:/ /mnt/sshftp

Connect Excel to PostgreSQL through SSH Tunnel (Part 2)

Now that you have setup your SSH tunnel using Putty It’s time to get excel involved. (Not there yet? go back to part 1)

You will need Office 2013 Professional to get access to the software and you will need to download Power Query from Microsoft. Here’s the current link http://www.microsoft.com/en-us/download/details.aspx?id=39379

Before you connect to a PostgreSQL database, the PostgreSQL .Net Data Provider needs to be installed. To install the PostgreSQL .Net Data Provider, see Install the PostgreSQL .Net Data Provider.

Once you’ve installed Power Query and the PostgreSQL adapter you are ready to open Excel. Navigate to the new Power Query tab and select From Database

Power Query From Database

Power Query From Database

You’ll get a popup to setup your database

Power Query PostgreSQL Database Connection Popup

 

Server will be localhost and the tunnel port that you setup before. If you’re following along closely we setup localhost and used the default value of 5432. This plugin doesn’t appreciate non-default port numbers so be sure to use the default.
Database is the name of your target database on the server

You will need to enter your database username and password also. You will likely get the following popup which is a good sign and you should accept.

Power Query Encryption Popup

Power Query Encryption Popup

If you run into trouble leave a comment and I’ll see if I can help.

Connect Excel to PostgreSQL through SSH Tunnel (Part 1)

This is a solution I managed to cobble together through trial and error and a lot of web searching. The fundamentals will be applicable to any remote database and should save you a lot of time searching.

1) Setup the tunnel with Putty.
Download Putty Here if you need it: http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe

Once installed you need to create a session. It’s important to do this first as putty likes to delete configurations when you change the settings:

Host name will be the remote server that hosts the database: something like www.mywebserver.com

Putty Configure Settings

Putty Configure Settings

It’s good to test this connection before going forward.

Once you have confirmed your connection to be functional you will need to reopen putty and setup your sever connection again. This time give it a name in “Saved Sessions” and click “Save” to store the configuration.

Next navigate to the Tunnels Section of the Connection > SSH menu

Putty SSH Tunnel

Putty SSH Tunnel

This is where you are going to define your local redirect settings:
Source Port is for the port on your computer that will be used for the connection (typically called localhost)
Destination is the location on the remote server that you need to access. For me and for most databases this is going to be localhost again. Be sure to include the port number for the database. PostgreSQL uses 5432 by default. (It’s important to use the default because the excel addin only supports default port numbers) (127.0.0.1 is interchangeable with localhost and just means redirect to the computer I’m on)

Putty Tunnel Setup

Putty Tunnel Setup

Go back to Session and be sure to Save your configurations otherwise they will be lost next time you start putty. Like I said, Putty really likes to delete configurations.

You’ll get this screen to login and once complete your tunnel will be setup!

Putty Login Screen

Putty Login Screen

Continue to Part 2 – Setting up Excel