一 概述
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