排查sshfs挂载失败的问题

排查sshfs挂载失败的问题

写代码在Linux上运行,但是熟悉的IDE(比如VS code)在自己的电脑上,可以使用sshfs把linux上的目录挂载到本地,再用VScode打开即可,可以使用下面的命令:

sshfs -odebug,sshfs_debug,loglevel=debug  -o rw,allow_other,uid=1190,gid=1190,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,IdentityFile=/Users/harlanc/.privateKey harlanc@192.168.23.2:/data1/workspace/mount/ffmpeg /Users/harlanc/workspace_ffmpeg

但是今天碰到一个问题,在别的CentOS机器上没问题,但是到192.168.23.2这台机器却连不上,报如下错误:

SSHFS version 2.5
FUSE library version: 2.9.9
nullpath_ok: 0
nopath: 0
utime_omit_ok: 0
executing <ssh> <-x> <-a> <-oClearAllForwardings=yes> <-ologlevel=debug> <-oServerAliveInterval=15> <-oServerAliveCountMax=3> <-oIdentityFile=/Users/    harlanc/.privateKey> <-2> <harlanc@192.168.23.2> <-s> <sftp>
debug1: Reading configuration data /Users/harlanc/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to 192.168.23.2 [192.168.23.2] port 22.
debug1: Connection established.
debug1: identity file /Users/harlanc/.privateKey type -1
debug1: identity file /Users/harlanc/.privateKey-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.8
kex_exchange_identification: read: Connection reset by peer
Connection reset by 192.168.23.2 port 22
remote host has disconnected

服务端主动断开链接了,查看服务端的ssh服务:

[root@harlanc]# netstat -nltp | grep sshd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1085/sshd
tcp6       0      0 :::22                   :::*                    LISTEN      1085/sshd

在查看一下ssh进程的具体信息:

[root@ harlanc]# ps -ef | grep 1085
root        1085       1  0 15:39 ?        00:00:00 /usr/local/sbin/sshd -D

[root@ harlanc]# rpm -qf /usr/local/sbin/sshd
***openssh-6.7.x86_64 //这里***是我们公司的名字

原来用的是我们公司自己的ssh服务。

而在可以连上的CentOS机器上,使用的是openssh这个开源ssh服务,把我们的服务替换成openssh不太现实,可以把openssh服务换一个端口启动起来:

 vim /etc/ssh/sshd_config

找到

 Port 22 

替换成

 Port 23

把openssh启动起来:

[root@ harlanc]# systemctl start sshd

这下两个服务都起来了:

[root@ harlanc]#  netstat -nltp | grep sshd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1085/sshd
tcp        0      0 0.0.0.0:23              0.0.0.0:*               LISTEN      316299/sshd
tcp6       0      0 :::22                   :::*                    LISTEN      1085/sshd
tcp6       0      0 :::23                   :::*                    LISTEN      316299/sshd

使用sshfs挂载的时候指定一下端口:

 sshfs -p 23 -odebug,sshfs_debug,loglevel=debug  -o rw,allow_other,uid=1190,gid=1190,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,IdentityFile=/Users/harlanc/.privateKey harlanc@192.168.23.2:/data1/workspace/mount/ffmpeg /Users/harlanc/workspace_ffmpeg

最后终于挂载上了。

 harlanc@APB ~ % df -h
Filesystem                                                        Size    Used   Avail Capacity iused ifree %iused  
harlanc@192.168.23.2:/data1/workspace/mount/ffmpeg   295Gi   237Gi    58Gi    81%    1.4M   18M    7%   /Users/harlanc/workspace_ffmpeg