Hi folks.
I have decided to re-post this because after 2 or 3 years of using this setup I am still loving it… and after few tiny modifications (mostly text formatting) here it is.
I have a machine that runs ssh server. That’s nothing new. Neither is it worth mentioning under normal circumstances… Recently I have purchased a 2 TB Western Digital MyBook USB 3.0 hard drive and I was going to use it to backup all my data. Why not make it a network shared drive I thought. It will make my life much easier if I could access the data from all my machines? Not a bad idea… I know… but I am not going to setup samba or nfs. I don’t want to make it a “network” drive. I want to have it mounted as a local drive on every machine that I use without a big fuss… How do I go about it?
I assume that You have drive attached to the ssh server running machine and that it’s mounted and that You have read and write permissions granted to Your user. I am using static IPs in my network – this is making things much easier for me as well.
In my case the drive is mounted on the server (IP 192.168.0.1 and port 20202) as /media/1862_GB_X-Ternal/ and my user andrzejl is the only user that is allowed to write to and read from it.
Now it’s time to prep the client machine. It’s really simple…
I want to have my drive mounted on my ssh client machines in /media/1862_GB_X-Ternal/ folder but I want to mount it as user (andrzejl) – not as root.
First I had to open terminal and gain root’s privileges by issuing:
su
and giving a root’s password.
Next I had to create my mount point:
mkdir -p /media/1862_GB_X-Ternal/
and make andrzejl owner of it:
chown -Rf andrzejl:andrzejl /media/1862_GB_X-Ternal/
Now that I had the folder ready I needed a package that would allow me to work with sshfs / sftp file system so in the same terminal I ran:
pacman -S sshfs
After the package was downloaded and installed I could close this terminal window and open another one. I needed to drop the root’s privileges as I want to do the rest of this as a user.
The syntax of the command looks like this:
sshfs -p sshSERVERport loginTOtheSSHserver@IPorHOSTNAMEofTHEsshServer:/where/is/the/drive/mounted/on/the/server/ /where/to/mount/on/local/machine/
Now… if I will start filling the data in this command I get this:
sshfs -p 20202 andrzejl@192.168.0.1:/media/1862_GB_X-Ternal/ /media/1862_GB_X-Ternal/
After running this command and typing in the password (if You got the syntax right) You should find all Your data on Your ssh client machine mounted in /media/1862_GB_X-Ternal/ ready to be read and modified by Your user.
Now…
IF You want the data to be auto-mounted at startup without typing in the password follow this post. Passwordless SSH authentication. Using authentication keys
You also need to create a mountsshfsshare.sh script in your ~/.kde4/Autostart folder and make it executable.
Here is how I do it under KDE4.
Open terminal. Type in:
touch ~/.kde4/Autostart/mountsshfsshare.sh
chmod +x ~/.kde4/Autostart/mountsshfsshare.sh
echo "sshfs -p 20202 andrzejl@192.168.0.1:/media/1862_GB_X-Ternal/ /media/1862_GB_X-Ternal/" > ~/.kde4/Autostart/mountsshfsshare.sh
Don’t forget to modify the sshfs line to suite Your needs.
Just to check run this:
cat ~/.kde4/Autostart/mountsshfsshare.sh
It should spit out:
sshfs -p 20202 andrzejl@192.168.0.1:/media/1862_GB_X-Ternal/ /media/1862_GB_X-Ternal/
or whatever command You use to mount the sshfs share. Now You can reboot the ssh client machine for testing purposes. If You did everything properly – You will have a mounted drive waiting for You next time You boot up Your machine.
Edit 01: Sometimes .sh script will not work. Try creating .desktop file then instead.
Remove the .sh file first.
rm -f ~/.kde4/Autostart/mountsshfsshare.sh
Now create the .desktop file.
touch ~/.kde4/Autostart/mountsshfsshare.desktop
Now edit the file using Your favorite editor. I will use mcedit here. Paste this into it:
[Desktop Entry]
Comment[en_US]=Mount SSHFS automagically.
Comment=Mount SSHFS automagically.
Encoding=UTF-8
Exec=sshfs -p 20202 andrzejl@192.168.0.1:/media/1862_GB_X-Ternal/ /media/1862_GB_X-Ternal/ &
GenericName[en_US]=
GenericName=
Icon=xterm-terminal
MimeType=
Name[en_US]=sshfs_mount
Name=sshfs_mount
Path=
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=
Do not forget to change the sshfs line. Now save the file and reboot for testing.
Edit 02: I like this setup very much for a good few reasons. Here are just a few:
a) hard drive is being shared over the network but it feels and acts like a local drive
b) it’s not accessible by the windows machines without specific setup
c) it’s easy to setup permissions to the drive so only one user or group can have full access to the drive. You can have some folks to see the drive as read only while You keep the privileges to write to it.
d) like everything that runs via ssh the traffic between you and the hdd is encrypted
Cheers.
Andrzej