Centos sshfs的安装和使用

一、演示环境:

[root@mgr02 ~]# cat /etc/hosts
10.0.0.7 mgr02
10.0.0.131 mgr03

[root@mgr03 ~]# cat /etc/hosts
10.0.0.7 mgr02
10.0.0.131 mgr03

二、服务器间免秘钥配置

在10.0.0.131 机器上安装 sshfs;通过sshfs 映射挂载10.0.0.7 机器上的/data1 目录到本地挂载点/mnt 下:

10.0.0.7 和10.0.0.131 机器上都执行# sshd-keygen -t rsa 生产秘钥对
拷贝10.0.0.131 上的公钥到10.0.0.7 上
[root@mgr03 ~]# ssh-copy-id -i .ssh/id_rsa.pub  -p52110 root@10.0.0.7

[root@mgr03 ~]# cat .ssh/config 
HOST 10.0.0.7
     HostName mgr02
     Port 52110
     User root
     IdentityFile ~/.ssh/id_rsa
     UserKnownHostsFile /dev/null
     StrictHostKeyChecking no

[root@mgr03 ~]# ssh root@10.0.0.7
Warning: Permanently added '[mgr02]:52110,[10.0.0.7]:52110' (ECDSA) to the list of known hosts.
Last login: Wed Jul 10 07:30:55 2019 from mgr03
[root@mgr02 ~]# 
[root@mgr02 ~]# 

面秘钥配置成功了

三、安装sshfs

此次演示采用 yum 安装sshfs
默认源无该工具,需要先安装EPEL源

yum install -y epel-release
yum -y install fuse-sshfs

[root@mgr03 ~]# which sshfs
/usr/bin/sshfs

[root@mgr03 ~]# cat /usr/lib/systemd/system/sshfs-diankezk.service
[Unit]
Description=SSHFS MOUNT mgr02 10.0.0.7
After=sshd.service

[Service]
Type=forking
ExecStart=/usr/bin/sshfs 10.0.0.7:/data1 /mnt -o reconnect -o cache=yes -o allow_other
ExecStop=/usr/bin/umount /mnt

[Install]
WantedBy=multi-user.target

开机自启动挂载:

[root@mgr03 ~]# systemctl enable sshfs-diankezk.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/sshfs-diankezk.service to /usr/lib/systemd/system/sshfs-diankezk.service.
上一篇:linux – sshfs – 找不到设备


下一篇:linux – sshfs“通过peer重置连接”和标识文件