1. 开启远程服务的ssh的22端口
sudo apt-get install openssh-server
2. 安装sshfs
2.1 ubuntu
apt-get install sshfs
2.2 Fedore
yum -y install fuse-sshfs
2.3 Centos
2.3.1 yum安装
yum -y install epel-release
yum -y install fuse-sshfs
yum list fs-sshfs
2.3.2 rpm安装
下载rpm文件
wget http://ftp.tu-chemnitz.de/pub/linux/dag/redhat/el7/en/x86_64/rpmforge/RPMS/fuse-sshfs-2.5-1.el7.rf.x86_64.rpm
需要先下载安装fuse(安装fuse-sshfs依赖于fuse)
yumdownloader fuse-libs
yumdownloader fuse
rpm -Uvh fuse-libs-2.9.2-7.el7.x86_64.rpm
rpm -Uvh fuse-2.9.2-7.el7.x86_64.rpm
安装fuse-sshfs
rpm -ivh fuse-sshfs-2.2-1.el7.rf.x86_64.rpm
2.3.3 编译安装
下载:https://github.com/libfuse/sshfs/releases
./configure --prefix=/usr/local/sshfs
make
make install
sshfs使用-挂载目录
语法:
sshfs user@hostname:path mout_point
举例:
先创建一个挂载点目录
mkdir /mnt/sftpSrvData
挂载远程目录到本地挂载点目录:
本地服务器
sshfs -o ro root@127.0. 0. 0:/opt/sftpSrvRootDir /mnt/sftpSrvData
远程服务器
sshfs -o ro root@192.168.100.111:/opt/sftpSrvRootDir /mnt/sftpSrvData
常用参数
-o ro: 只读方式挂载。如果不指定参数,默认是读写方式挂载。
-o rw: 读写方式挂载。如果不指定参数,默认读写方式挂载。
设置开机启动
vim /etc/fstab
sshfs#user@hostname:path mount_point fuse defaults,auto,allow_other 0 0
#需要设置服务器之间允许SSH无密码登录,系统重启之后才能自动挂载文件系统。
#如果服务器配置为基于SSH密钥的认证方式,则/etc/fstab中加入如下行:
sshfs#user@hostname:path mount_point fuse IdentityFile=~/.ssh/id_rsa defaults,auto,allow_other 0 0
#接下来,你需要更新 fstab 文件使修改生效。
mount -a
3.卸载挂载目录
fusermount -u mount_point
如果出现提示:device is busy
可继续通过下面命令卸载:
umount -fl ./sftpSrvData
常见问题:
操作权限问题
出现执行挂载命令以后,shell命令可以直接进入挂载点操作,但远程程序一直无法操作成功。原因是需要加上 -o 参数:
sshfs root@192.168.100.111:/opt/sftpSrvRootDir /mnt/sftpSrvData -o allow_other
如果使用-o参数,需要增加一个配置文件:/etc/fuse.conf,添加一行记录,
vim /etc/fuse.conf
user_allow_other
注:
wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh
chmod u+x bbr.sh
./bbr.sh
sysctl
lsmod | grep bbr
ssh -l server 192.168.56.1
yum -y install fuse fuse-* glib2 glib2-*
sshfs server@192.168.56.1:/home/server/workspace /data/www
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub server@192.168.56.1
vim /etc/fstab
umount -fl /data/www/