挂载远程目录到本地

Linux使用sshfs挂载远程目录到本地

1.远程服务器安装ssh

## centos
sudo yum install openssh openssh-server 

## deepin
sudo apt install ssh openssh-server

2.本地主机安装 sshfs

## deepin
sudo apt install ssh sshfs

本地主机是centos查看步骤5,因为在测试中发现一些问题。

3.挂载

sshfs -p port root@ip:/path  

如:远程服务器:
目录: /mnt/software
ip:122.141.78.230
端口号:2222
将它挂载到本机/mnt/remote目录中:

sudo mkdir /mnt/remote
sudo sshfs -p 2222 [email protected]:/mnt/software  /mnt/remote

4.卸载

umount /mnt/remote

5.CentOS主机挂载远程目录

CentOS系统sshfs不在软件源中,需要添加epel源:

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

也可以手动下载安装:

# CentOS7:
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
# CentOS6:
wget http://ftp.tu-chemnitz.de/pub/linux/dag/redhat/el6/en/x86_64/rpmforge/RPMS/fuse-sshfs-2.5-1.el6.rf.x86_64.rpm
# 安装
rpm -ivh fuse-sshfs-2.5-1.el6.rf.x86_64.rpm 

6.错误分析

(1)read: connection reset by peer

网络故障:
查看服务器防火墙限定;
查看ssh的最大连接数,超过之后会服务器端会拒绝新的连接,直到有新的连接释放出来;
查看/etc/hosts.allow和/etc/hosts.deny配置文件限定ip登录
最后查看ssh是否安装

# 安装ssh
sudo yum install openssh
sudo yum install openssh-clients

(2)挂载完成之后,非管理员用户访问不了,只能通过root访问,加上allow_other选项即可:

sudo sshfs -p 2222 -o allow_other [email protected]:/mnt/software  /mnt/remote

(3)fuse: mountpoint is not empty,非空挂载,添加nonempty

sudo sshfs -p 2222 -o allow_other -o nonempty  [email protected]:/mnt/software  /mnt/remote

你可能感兴趣的:(挂载远程目录到本地)