Archive for the ‘linux’ Category

Mounting a remote ssh filesystem using sshfs on Ubuntu

Saturday, February 2nd, 2008

I am working on a Linux computer at the University with a RedHat Entreprise distribution. There I have all my work that:

  1. I wish to have as backuped as possible;
  2. I wish to have easily accessible from my laptop, to upload and download.

I looked for ways to do it and I found sshfs. In this way, as I will show you, whenever I log in to my laptop, with an internet connection available, I have a virtual folder where I have a seamless access to all the files on my pc at the University. This is how I did it:

  1. Enabled the Multiverse on the Synaptics software sources. Went to System–> Administration –> Software sources, then on the Ubuntu software tab, checked the fourth option (Multiverse).
  2. Installed sshfs:
    sudo apt-get install sshfs
  3. Once installed, changed the permissions so that I could mount it as normal user:
    sudo chmod +x /usr/bin/fusermount
  4. Made a mount point directory on my laptop that points to the directory I am mounting on the other machine. In this case I created a directory named lraero19 (which is the name of my computer at the university) on the /media directory:
    sudo mkdir /media/lraero19
  5. Then changed the owner to me:
    sudo chown gorkiana /media/lraero19
  6. Afterwards I had to add my user to the group “fuse” so that I could use it. For that I typed:
    sudo adduser gorkiana fuse

    Then I had to logout and login back again so that the change took effect.

  7. Mounted the remote drive with sshfs. For this I typed in:

    sshfs my_user_name@ip_at_university:/the_directory_to_mount /media/lraero19

  8. To unmount I just type:
    fusermount -u /media/lraero19

Since I have to do this every time I logged in, I decided to automate the process. For that I needed first to get rid of the password prompt. Hence I did this:

  1. I had to create a public key on my laptop and copy it to the university computer so that I did not need to type in the password every time. Typed:
    ssh-keygen -t rsa

    (typed enter to the both question since I do not want a password).

  2. Made a directory named .ssh at my home directory at the university computer:
    mkdir /media/lraero19/.ssh

    (now I can do it as if it was a local directory :-) ).

  3. Then chmoded it:
    chmod 700 /media/lraero19/.ssh
  4. Copied the public key to there:
    cat .ssh/id_rsa.pub >> /media/lraero19/.ssh/authorized_keys
  5. Chmoded it:
    chmod 600 /media/lraero19/.ssh/authorized_keys

Then I wanted it to run everytime I logged in to GNOME, for that I just went to Sytem –> Preferences –> Sessions, then at the startup programs tab just added one more, with the command:

sshfs my_user_name@ip_at_university:/the_directory_to_mount /media/lraero19

Finally I had to get a way of unmounting the drive when I logged out. After many hours googling I found a solution! Edited the file: /etc/gdm/PostSession/Default and added the following line before the exit 0 line:

fusermount -u /media/lraero19

del.icio.us Slashdot Digg Technorati Google StumbleUpon