使用SSHfs把远程文件系统挂载到本地目录

土豆条
土豆条 2016-7-3

Ubuntu/Debian系统安装

需要用到的模块程序

sudo apt-get install sshfs


下面命令加载此模块

sudo modprobe fuse


一些权限命令,username 可以自定义

sudo adduser <username> fuse
sudo chown root:fuse /dev/fuse
sudo chmod +x /dev/fusermount


用户添加到了fuse组后,先重新登录下


创建一个需要挂载的本地目录(远程目录也是已存在的目录)

mkdir /你的目录/localpath2remote


执行挂载

sshfs <username>@<ipaddress>:/remotepath /你的目录/localpath2remote


这样操作本地目录“localpath2remote” 相当于操作远程目录 remotepath


注:

如果希望其他用户可以访问本目录需要允许 增加允许

使用-o allow_other需要更改文件/etc/fuse.conf,将#user_allow_other 的#删除


如果挂载已经建立 需要先卸载挂载,并重新建立挂载


卸载挂载命令

fusermount -u /你的目录/localpath2remote
或者
umount /挂载点


重新建立挂载

sshfs -o allow_other <username>@<ipaddress>:/remotepath /你的目录/localpath2remote


centos系统安装

最新版本安装GIT发布地址
https://github.com/libfuse/sshfs/releases

下载最新版本到服务器后解压并安装

./configure
make && make install


创建挂载目录

mkdir /var/mnt


执行挂载

sshfs <username>@<ipaddress>:/remotepath /你的目录/localpath2remote


注意:

  • 当挂在服务器间SSH网络不稳定,SSH一旦断开挂载即会中断;

常见问题:

1、configure: error: Package requirements (fuse >= 2.3 glib-2.0 gthread-2.0) were not met

yum -y install fuse fuse-* glib2 glib2-*


回帖
  • 消灭零回复

微信二维码

微信二维码

微信扫码添加微信好友