Purpose: to mount a remote directory on my local Ubuntu Linux Desktop system using SFTP (which is SSH in an FTP-like fashion). The goal is to easily gain access to a remote system’s files through another folder on my desktop. Debina/Ubuntu allows you to easily mount SSH folders via the GUI, however, these mounts won’t show up in the terminal (and in some programs). I used sshfs to accomplish this.
Special Thanks: goes to user llamakc from ubuntuforums.org for helping me with this one night in this thread; also, can find Ubuntu’s SSHFS documentation here.)
install the sshfs software and mount
After some trial and error on my part, I found that only a few simple steps are needed to get everything up and running:
First, get the sshfs software (which is based on FUSE); if you have Ubuntu, this is easy because it is an included package available for easy install. After the package is installed, you need to add your username to the fuse
group. On Ubuntu, you would open a terminal window and perform the following:
sudo aptitude update
sudo aptitude install sshfs
sudo adduser yourusername fuse
After, restart your machine. (I have tried just logging in and logging out, but I kept getting permissions errors — all of which disappeared after a restart.)
The next step it so to create an empty directory that will serve as the “window” into the SFTP server. I created a folder on my desktop called sftp
. Once the folder has been created, simply run sshfs
using the appropriate login information (host username and IP), the host and local directories, and the SFTP connection is mounted on a folder on my desktop.
mkdir ~/Desktop/sftp
sshfs HOSTuser@remote.host.or.ip:/host/dir/to/mount ~/Desktop/sftp
This folder will work like any other folder on your system; when you restart your computer (or logout and log back in) you will have to go through the last step of the process again (calling the sshfs
program) to enable the folder on your desktop (save time by creating a bash alias).
possible errors and workarounds
When I restarted my system the first time (using Ubuntu 6.06), after having so cleverly got sshfs
to work, and tried to run my sshfs
command I got an error:
sshfs HOSTuser@remote.host.or.ip:/host/dir/to/mount ~/Desktop/sftp
fusermount: failed to open /dev/fuse: No such file or directory
A quick search on google brought me to the sourceforge FAQ for sshfs and there, lo and behold, the following was suggested to rectify the situation:
sudo mknod -m 666 /dev/fuse c 10 229
After running this command, I was able to mount my SFTP directory. I never received this error using Ubuntu 6.10.
If you get any permission denied warnings, be sure you have added your username to the fuse
group and also restarted your system.
create a bash alias to save time and typing
To save time, I created a bash alias that would remember all the details for me (thanks to El Pato for the naming suggestions).
First, make make sure my system reads from the ~/.bash_aliases
file (it may not be default). Open ~/.bashrc
and ensure the following lines are uncommented:
# Alias definitions. # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding them here directly. # See /usr/share/doc/bash-doc/examples in the bash-doc package. if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi
Next, create (or modify if you already have one) your ~/.bash_aliases
file.
nano ~/.bash_aliases
I added the following single line of code to the document (first call the mknod
, if you are getting the error, then the sshfs
):
alias dt-sftp='sudo mknod -m 666 /dev/fuse c 10 229; sshfs HOSTuser@remote.host.or.ip:/host/dir/to/mount ~/Desktop/sftp'
Now, when I open the terminal, I just type (of course, you can name it whatever you want):
dt-sftp
And everything loads correctly. Is very fast and very nice. I like it. Changes to your ~/.bash_aliases
file will only take effect after you have reopened the terminal or called:
. ~/.bash_aliases
finally:
If you ever want to unmount the directory without logging out or restarting, use the following:
fusermount -u ~/Desktop/sftp