SSHFS核心特性解析
SSHFS的主要特性包括:
它依赖于FUSE(Linux环境下优秀的用户空间文件系统框架)进行构建。
具备多线程处理能力,允许在服务器端并发处理多个请求。
支持大尺寸的数据读取操作,单次最大读取量可达64k。
内置缓存机制,能够缓存目录内容以提升访问效率。
安装fuse-sshfs组件
第一步:安装fuse-sshfs组件
对于CentOS或RHEL用户,fuse-sshfs位于EPEL仓库中,因此需确保系统已启用EPEL源。随后执行以下命令完成安装。
在CentOS/RHEL系统上的操作如下:
#yum install fuse-sshfs
在Ubuntu和Debian系统上的操作如下:
$ sudo apt-get update
$ sudo apt-get install sshfs
手动挂载远程目录
第二步:挂载远程目录
接下来使用sshfs挂载远程服务器的目录,请确保远程系统运行的SSH服务与本地系统的连接配置正确无误。
首先创建本地的挂载点目录
# mkdir /mntssh
现在执行远程目录的挂载操作。本例中,我们将把IP为192.168.1.12(主机名remote.example.com)远程系统中的/home/remoteuser目录,挂载到本地系统的指定位置。
# sshfs laitkor@remote.example.com:/home/remoteuser /opt/mntssh
示例输出结果
The authenticity of host 'remote.example.com (192.168.1.12)' can't be established.
RSA key fingerprint is 77:85:9e:ff:de:2a:ef:49:68:09:9b:dc:f0:f3:09:07.
Are you sure you want to continue connecting (yes/no)? yes
remoteuser@remote.example.com's password:
验证挂载状态
第三步:验证挂载状态
在本地挂载点上成功挂载远程文件系统后,可以通过运行mount命令来验证挂载是否生效。
# mount
/dev/mapper/vg_svr1-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)
/dev/sda1 on /boot type ext4 (rw)remoteuser@remote.example.com:/home/remoteuser on /mntssh type fuse.sshfs (rw,nosuid,nodev)
此外,导航至挂载点目录并使用ls命令,即可看到来自远程系统的文件列表。
# cd /mntssh
# ls
配置开机自动挂载
第四步:配置系统启动时自动挂载
若希望每次系统重启时自动挂载该远程文件系统,需在/etc/fstab文件中添加相应条目。请注意,必须确保远程和本地系统之间已配置好基于密钥的SSH认证。
remoteuser@remote.example.com:/home/remoteuser /mntssh fuse.sshfs defaults 0 0
卸载远程目录
第五步:卸载目录
当工作完成且不再需要已安装的目录时,只需使用以下命令将其卸载。
#umount / mntssh