SSH - SSHFS - FUSE

Preface

Most probably many of you do have access to some server with unused HDD space at network. According to this it would be probably handy to use this space.

In the case that you have a server on public internet and you are using more as one PC (at home, in office, at school,….) you can use it as well as network files stem / storage / shared disk / … .

As you can see I have not mentioned word “cloud”. To be honest today many companies are taking technologies that have been already present for couple of years and are doing just / only great marketing for them and are calling them “cloud”.

The result is that no one really know if you are going to buy just Virtual Server, Disk space, Application running on cluster, … ; but it’s any time really powerful according to marketing slides.

Just for fun: “ The Rolling Stones - Get Off of My Cloud (1967)

Install

We will need to install some additional software that will enable us to access the SSH server in the same was as we would access SFTP and in same time present this like file system.

According to this we will need to install on SSH Client site :
Sshfs – This will provide the access to SSH Server similar to how SFTP connection
fuse - This will provide file system access to established SSH connection (in user space memory). According to this it will be possible to mount mentioned file system like standard HDD.

CentOS / RHEL

EPEL (install)

CentOS 6 - 32-bit
[root@SSH_Client ~]# rpm -Uvh http://mirror.overthewire.com.au/pub/epel/6/i386/epel-release-6-8.noarch.rpm

CentOS 6 - 64-bit
[root@SSH_Client ~]# rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

CentOS 5 - 32-bit
[root@SSH_Client ~]# rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

CentOS 5- 64-bit
[root@SSH_Client ~]# rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

Install ''fuse'' ''sshfs''

[root@SSH_Client ~]# yum -y install fuse sshfs

Load "fuse" module in kernel

[root@SSH_Client ~]# lsmod | grep fuse                                 # Check if it is already loaded

[root@SSH_Client ~]# modprobe fuse                                     # When not, load it

[root@SSH_Client ~]# lsmod | grep fuse                                 # Check if it was loaded
fuse                   73530  0

To make it persistant you will need to do this:

[root@SSH_Client ~]# echo "modprobe fuse">> /etc/rc.local      # After boot module will be loaded

Mount Remote FS

[user@SSH_Client ~]$ sshfs user@SSH_Server:/home/user/share ~/share                       # Mount Remote FS
user@ssh_server's password:

[user@ssh_Client ~]$ df                                                                   # Check if it we can use it
Filesystem                 1K-blocks    Used Available Use% Mounted on
/dev/mapper/vg_dd2-lv_root   6926264 2020996   4553424  31% /
tmpfs                         510172       0    510172   0% /dev/shm
/dev/sda1                     495844   34540    435704   8% /boot
user@SSH_Server:/home/user/share       6926264 2056700   4517720  32% /home/user/share    # we can see it

[user@SSH_Client ~]$ mount                                                                # Check how it is mounted
/dev/mapper/vg_dd2-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
user@SSH_Server:/home/user/share on /home/user/share type fuse.sshfs (rw,nosuid,nodev)    # here we can see our remote FS

In this case we will use local UID and GID as our user account on SSH Server. According to this you do not really need to change it in the case that you are going to use same remote FS on several SSH Clients. On another hand it is possible to optimize it with using “ –o “ option.

Additional options ( -o ):
hard_remove - This will remove the data on Remote FS immediately
intr - Enable I/O interruptions
sshfs_sync - This is writing immediately to Remote FS
reconnect - After breaking SSH session it will automatically reconnect
follow_symlinks - On SSH Server site it will synchronize simlinks

Umount Remote FS

[user@SSH_Client ~]$ fusermount -u ~/share                                       # Umount the remote FS

[user@SSH_Client ~]$ df                                                          # It was unmounted
Filesystem                 1K-blocks    Used Available Use% Mounted on
/dev/mapper/vg_dd2-lv_root   6926264 2020996   4553424  31% /
tmpfs                         510172       0    510172   0% /dev/shm
/dev/sda1                     495844   34540    435704   8% /boot

[user@SSH_Client ~]$ mount                                                      # It was unmounted
/dev/mapper/vg_dd2-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

URL's

Navigation
Print/export
QR Code
QR Code wiki:infrastructure_tools:ssh:ssh-sshfs-fuse (generated for current page)