Linux系统--sshfs挂载出现read: Connection reset by peer错误的解决方法

一 概述
SSHFS(SSH Filesystem)是一种通过普通ssh连接来挂载和与远程服务器或工作站上的目录和文件交互的文件系统客户端,其通过 SSH 文件传输协议(SFTP)挂载远程的文件系统并且在本地机器上和远程的目录和文件进行交互,实际场景中,我主要在挂载后创建各个库文件所在路径的软链接,用于交叉编译。

二 一般用法
首先在本地主机上创建挂载点,如:/home/barry/armbian/mntsysroot_arm32

然后执行如下命令将远程主机的根目录挂载到上面挂载点上:

sudo sshfs pi@192.168.50.191:/ /home/barry/armbian/mntsysroot_arm32/ -o transform_symlinks -o allow_other

三 遇到的问题
在一次挂载时,遇到一下问题

read: Connection reset by peer
尝试在要挂载的主机进行各种设置,包括关闭防火墙等操作之后仍有此问题。

四 问题定位与解决
使用一下命令尝试挂载,可以跟踪问题

sudo sshfs pi@192.168.50.191:/ /home/barry/armbian/mntsysroot_arm32/ -o debug -o sshfs_debug

运行之后有以下输出:

SSHFS version 2.5
FUSE library version: 2.9.4
nullpath_ok: 0
nopath: 0
utime_omit_ok: 0
executing <ssh> <-x> <-a> <-oClearAllForwardings=yes> <-2> <pi@192.168.50.191> <-s> <sftp>
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:DaNpvGDbPRvXRvCDApXUMss56ufPqZux/DDEZ7UxitQ.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:2
remove with:
ssh-keygen -f "/root/.ssh/known_hosts" -R 192.168.50.191
ECDSA host key for 192.168.50.191 has changed and you have requested strict checking.
Host key verification failed.
read: Connection reset by peer


可以看到是由ssh公钥认证导致的,根据上面提示的命令,清除之前对应IP保存的密钥:

ssh-keygen -f "/root/.ssh/known_hosts" -R 192.168.50.191

然后再输入之前的挂载命令根据提示输入密码等操作之后,挂载成功。

sudo sshfs pi@192.168.50.191:/ /home/barry/armbian/mntsysroot_arm32/ -o transform_symlinks -o allow_other
原文地址:https://www.cnblogs.com/dancesir/p/13344549.html