Samba Fileserver Through SSH Tunnel Over WAN

Step 10: Samba Fileserver Through SSH Tunnel Over WAN

Picture of Samba Fileserver Through SSH Tunnel Over WAN
Screen shot 2012-08-07 at 1.45.54 PM.png
Now, time for the real meat of this project!  A distributed file system (like Samba or NFS) works nicer than many other solutions for cloud serving because it will mount the server’s drive to the local filesystem (as opposed to only a web-interface or ftp/sftp browsing).  The effect is similar to plugging in a flash drive. The files aren’t actually stored on the local computer but you still have r/w access to everything. So editing documents, watching videos, listening to music, or whatever else can be done without needing to actually download anything and everything works quickly.  All of the traffic is encrypted with an SSH tunnel too, which keeps curious eavesdroppers away from your info and speeds up the file transfers.

What we’ll do first is ssh port forwarding to the server (the ARM computer) from the client computer (your computer).  This will forward all connections on a specific port from the client computer back to the server.  We can take advantage of this feature when connecting with samba!  For samba, we’ll actually tell it to mount the local computer on the port that is port forwarded so we connect back to our server through an ssh tunnel.

Here is the command to build the ssh port forwarding (use port 445 because this is the samba default port):
$ ssh -C -c blowfish -L8392:localhost:445 server_USERNAME@serverIP

-C is for data compression (speeds up connection)
-c blowfish is for the blowfish encryption algorithm which is secure but allows for faster connections than other algorithms
-L[bind_address:]port:host:hostport is for port forwarding
-p [server_port] not shown but can connect to SSH on a non-default port on the server (if you don’t like using port 22)

Then make a directory on your client computer where you’ll mount your server (for OS X I like doing /Users/my_username/mount_spot and dragging the mount_spot folder into the Finder sidebar):

$ mkdir /Users/username/mount_spot    <–(make this at the desired location)

Keep the window with ssh up and open a new shell (command line window), mounting Samba with this (NOTE: 8392 is a random number, switch it with whatever as long as it’s above 1000):

$ mount -t smbfs //server_USERNAME@localhost:8392/server_drive ~/mount_spot

Unmount the drive with this:
umount -t smbfs //server_USERNAME@localhost:8392/server_drive

Close SSH port forwarding by switching to the window with SSH and typing:
$ exit