Linux上通过SSH挂载远程文件系统方法详解

SSHFS的特点:

基于FUSE(Linux的最佳用户空间文件系统框架)

多线程:在服务器上可以有多个请求

允许大读取(最大64k)

缓存目录内容

步骤1:安装fuse-sshfs

对于centos/rhel用户,fuse sshfs在epel repository下可用,因此请确保在系统中安装了epel repository。现在执行以下命令安装它

在CENTOS/RHELL上:

  #yum install fuse-sshfs

在Ubuntu和Dabian上:

  $ sudo apt-get update    $ sudo apt-get install sshfs

步骤2:装载远程目录

让我们使用sshfs挂载远程服务器目录,确保远程系统运行的ssh服务器与系统的ssh连接正确。

首先创建装入点

  # mkdir /mntssh

让我们挂载远程目录。对于本例,我们将把/home/remoteuser目录从192.168.1.12(remote.example.com)系统安装到本地系统。

  # 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:

步骤3:验证安装

在本地挂载点上挂载远程文件系统后,通过运行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)

同样导航到你的挂载点,将从远程系统中看到文件

  # cd /mntssh    # ls

步骤4:在系统引导时挂载目录

如果要在每次系统重新引导时自动挂载远程文件系统,请在/ etc / fstab文件中添加以下条目。确保在远程和本地系统之间安装了基于密钥的ssh。

  remoteuser@remote.example.com:/home/remoteuser /mntssh fuse.sshfs defaults 0 0

步骤5:卸载目录

如果您的工作结束并且您不再需要已安装的目录,则只需使用以下命令卸载。

  #umount / mntssh

参与评论