sshfs远程挂载

Posted zhaojingyu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sshfs远程挂载相关的知识,希望对你有一定的参考价值。

一、什么是 SSHFS
SSHFS(Secure SHell FileSystem)是一个客户端,可以让我们通过 SSH 文件传输协议(SFTP)挂载远程的文件系统并且在本地机器上和远程的目录和文件进行交互。

centos:
yum install sshfs

ubuntu:
sudo apt-get install sshfs 

二、准备两台任意操作系统

一台
mkdir   /test/zjy/    

另一台
mkdir   /test/zjy/  

三、挂载

sudo sshfs -o nonempty,allow_other,exec   [email protected]:/test/zjy/ /test/zjy/
                       参数                用户@地址:挂载到               挂载到

nonempty 允许安装在非空文件/DIR上
allow_other 允许访问其他用户


mount -a       重新加载挂载信息

四、查看

查看当前系统挂载:
[[email protected] ~]# cat /etc/mtab
/dev/vda1 / ext3 rw,noatime,acl,user_xattr 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
devpts /dev/pts devpts rw,mode=0620,gid=5 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
[email protected]:/test/ /test/zjy fuse.sshfs rw,nosuid,nodev,allow_other 0 0



添加到自动挂载:
[email protected]:/test/ /test/zjy fuse.sshfs rw,nosuid,nodev,allow_other 0 0

五、卸载命令

umount -f /test/zjy/ 

六、如果想免秘钥(可以做ssh免秘钥)

1.ssh免秘钥登录/挂载:

ssh-keygen -t rsa
		  
[[email protected] ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
b0:9d:41:56:b5:c4:b2:0e:0d:47:07:4d:fa:4c:47:03 [email protected]
The key‘s randomart image is:
+--[ RSA 2048]----+
|        oo+*E.o  |
|       o. o+oo . |
|      . .+.oo .  |
|       +.oo+ .   |
|      . So  o    |
|          .      |
|                 |
|                 |
|                 |
+-----------------+

2.把公钥复制到服务器上

ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]

[[email protected] ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
[email protected]‘s password: 
Now try logging into the machine, with "ssh ‘[email protected]‘", and check in:

  .ssh/authorized_keys

to make sure we haven‘t added extra keys that you weren‘t expecting.


3.测试
[[email protected] ~]# ssh [email protected]


测试成功在挂载就不需要数据密码 



以上是关于sshfs远程挂载的主要内容,如果未能解决你的问题,请参考以下文章

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

sshfs远程挂载

sshfs通过ssh挂载远程目录到本地

linux sshfs远程挂载文件到本地目录

sshfs 本地挂载远程目录

工具篇:远程挂载工具 sshfs