In the previous chapter, we worked through SSH, which is a crucial utility that is used multiple times per day by most Linux administrators. But while it's great for accessing other Linux systems on your network, it also allows you to access remote filesystems as if they were mounted locally. This is known as SSHFS. One of the great things about SSHFS is that there is no need to clarify any exported directories before hand. If you're able to connect to a remote Linux server and access a directory via SSH, then you're automatically able to mount it locally as if it were a network share.
On Debian systems, you can simply install the sshfs
package. On CentOS, the sshfs
package is not available by default. Before you can install sshfs
on a CentOS system, you'll need to add a whole new repository, known as Extra Packages for Enterprise Linux (EPEL). To do that, simply install the epel-release
package:
# yum install epel-release
After installing the epel
repository, you should be able to install sshfs
:
# yum install sshfs
Once installed, you're able to mount directories on your local file system quite easily:
sshfs [email protected]:/home/jay/docs /home/jay/mnt/docs
In order to work, your user account must have access not only to the remote system, but also to the local mount point. Once you initiate the command, you'll see prompts similar to those you'd normally see while connecting to the server via SSH. Essentially, that's exactly what you're doing. The difference is that the connection remains open in the background, maintaining the relationship between the remote directory and the local directory.
Using sshfs
is a great idea for when you need to mount something on a remote filesystem, but you may not need to access it again or that often. But similar to NFS and Samba shares, you can actually use /etc/fstab
to mount a resource via SSHFS. Consider the following fstab
example:
[email protected]:/home/jay/docs /home/jay/mnt/docs fuse.sshfs defaults,noauto,users,_netdev 0 0
As we've done before, we set noauto
so that we can establish this connection by simply typing:
mount /home/jay/docs