Mounting a remote ssh filesystem using sshfs on Ubuntu
I am working on a Linux computer at the University with a RedHat Entreprise distribution. There I have all my work that:
- I wish to have as backuped as possible;
- 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:
- 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).
- Installed sshfs:
sudo apt-get install sshfs - Once installed, changed the permissions so that I could mount it as normal user:
sudo chmod +x /usr/bin/fusermount - 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 - Then changed the owner to me:
sudo chown gorkiana /media/lraero19 - Afterwards I had to add my user to the group “fuse” so that I could use it. For that I typed:
sudo adduser gorkiana fuseThen I had to logout and login back again so that the change took effect.
- Mounted the remote drive with sshfs. For this I typed in:
sshfs my_user_name@ip_at_university:/the_directory_to_mount /media/lraero19 - 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:
- 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).
- 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
). - Then chmoded it:
chmod 700 /media/lraero19/.ssh - Copied the public key to there:
cat .ssh/id_rsa.pub >> /media/lraero19/.ssh/authorized_keys - 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/lraero19Finally 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