Subscribe to PHP Freaks RSS

SSH Auto-mount Network Share

Print
by Timothy McKeown on Jun 12, 2009 11:00:37 AM - 9,899 views

(Beware - This blog/tutorial is directed towards linux based users)
When doing any type of work, especially web work, one of the royal pains is FTPing to your server, or any type of file transfer. Well now you can make it quick and painless. Let me introduce SSHFS. There are 3 major components when creating the SSHFS, and I will guide you through creating and installing all of the necessary steps. Now you can mount and use your file system to automatically upload files and folders to your server with ease.

The 3 Major components:

  1. SSH Automatic Login
  2. Install SSHFS
  3. Mount your folder(s)

SSH Automatic Login

Run this command (with the obvious variable substitutions). It should create a public ssh key on your server.

ssh-copy-id [-i [identity_file]] [user@]machine
  1. ssh-keygen -t dsa
  2. ssh-copy-id user@machiner.

Check to make sure it's there, the file should be called, "authorized_keys".

ls -al ~/.ssh/

If you're having trouble with this part, you can reference this tutorial which breaks this component into smaller steps: SSH Automatic Login.

Install SSHFS

sudo apt-get install sshfs

Or use whatever package manager your distribution provides.

Mount

Create a shell script, we'll call it "mount.sh", and add the contents:

sshfs [user]@[your_server].com:/dir/on/server /dir/to/mount

Run the script:

./mount.sh

Go to the mounted directory and run the 'ls' command to make sure all of your files/folders from your server show up in your local directory.

After you have this successfully working you should at it to your startup scripts.

System >> Preferences >> Sessions >> [add_a_new_entry]

You should be all set. You should have an automatic SSH login (no prompt for a password) from your computer to your server and a mounted folder to your server that acts as an automatic FTP client. The files in your mounted directory should be synced with that of your server. Now all you have to do is move or copy your desired files/folders into the mounted directory, and voila, they're on your server.

Comments

steviewdr Jun 19, 2009 8:49:15 AM

Yes, sshfs works very nicely indeed. I did have to do an additional step however after getting this error:
"failed to open /dev/fuse: Permission denied"

The following fixed that error:
sudo adduser user fuse
See: https://lists.ubuntu.com/archives/ubuntu-users/2006-June/080739.html

Timothy McKeown Jun 20, 2009 2:46:49 PM

Thank you. What version of Ubuntu are you running?

steviewdr Jul 1, 2009 8:31:23 AM

I was using Debian Lenny.

Add Comment

Login or register to post a comment.