Filesystem in Userspace
(
FUSE
) suite, which is what SSHFS uses as its
virtual filesystem to
facilitate such a connection. The
-u
option, as you've probably
guessed, is for unmounting the connection normally. There is also the
-z
option,
which unmounts the SSHFS mount
lazily
. By lazily, I mean it basically unmounts
the filesystem without any cleanup of open resources. This is a last resort that you
should rarely need to use, as it could result in data loss.
Chapter 12
[
323
]
Connecting to an external resource
via SSHFS can be simplified by adding an entry
for it in
/etc/fstab
. Here's an example entry using our previous example:
myuser@192.168.1.50:/share/myfiles /mnt/myfiles fuse.sshfs
rw,noauto,users,_netdev 0 0
Notice that I used the
noauto
option in the
fstab
entry, which means that your
system will not automatically attempt to bring up this SSHFS mount when it boots.
Typically, this is ideal. The nature of SSHFS is to create on-demand connections to
external resources, and we wouldn't be able to input the password for the connection
while the system is in the process of booting anyway. Even if we set up password-
less authentication, the SSH daemon may not be ready by the time the system
attempts to mount the directory, so it's best to leave the
noauto
option in place and
just use SSHFS as the on-demand solution it is. With this
/etc/fstab
entry in place,
any time we would like to mount that resource via SSHFS, we would only need to
execute the following command going forward:
mount /mnt/myfiles
Since we now have an entry for
/mnt/myfiles
in
/etc/fstab
, the
mount
command
knows that this is an SSHFS mount, where to locate it, and which user account to use
for the connection. After you execute the example
mount
command, you should be
asked for the user's SSH password (if you don't have password-less authentication
configured) and then the resource should be mounted.
SSH sure does have a few unexpected tricks up its sleeve. Not only is it the de facto
standard in the industry for connecting to Linux servers, but it also offers us a neat
way of transferring files quickly and mounting external directories. I find SSHFS
very useful in situations where I'm working on a large number of files on a remote
server but want to work on them with applications I have installed on my local
workstation. SSHFS allows us to do exactly that.
Summary
In this chapter, we explored multiple ways of accessing remote resources. Just about
every network has a central location for storing files, and we explored two ways of
accomplishing this with NFS and Samba. Both NFS and Samba have their place in
the data center and are very useful ways we can make resources on a server available
to our users who need to access them. We also talked about
rsync
and
scp
, two great
utilities for transferring data without needing to set up a permanent share. We closed
off the chapter with a look at SSHFS, which is a very handy utility for mounting
external resources locally, on demand.
Sharing and Transferring Files
Do'stlaringiz bilan baham: |