#常用命令 sshfs -o nonempty,reconnect,allow_other,exec -p22 zjy@172.21.0.10:/data/zjy /data/zjy cat /etc/fstab sshfs#zjy@172.21.0.10:/data/zjy /data/zjy fuse nonempty,reconnect,allow_other,exec 0 0
一、什么是 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 root@xx.xx.xx.xx:/test/zjy/ /test/zjy/ 參數 用戶@地址:掛載到 掛載到
nonempty 允許安裝在非空文件/DIR上
allow_other 允許訪問其他用戶
mount -a 重新加載掛載信息
四、查看
查看當前系統掛載: [root@xiaoyuer ~]# 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 root@192.168.1.121:/test/ /test/zjy fuse.sshfs rw,nosuid,nodev,allow_other 0 0 添加到自動掛載: root@192.168.1.121:/test/ /test/zjy fuse.sshfs rw,nosuid,nodev,allow_other 0 0
五、卸載命令
umount -f /test/zjy/
六、如果想免秘鑰(可以做ssh免秘鑰)
1.ssh免秘鑰登錄/掛載: ssh-keygen -t rsa [root@xiaoyuer ~]# 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 root@xiaoyuer 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 root@xx.xx.xx.xx [root@xiaoyuer ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.121 root@192.168.1.121's password: Now try logging into the machine, with "ssh 'root@192.168.1.121'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. 3.測試 [root@xiaoyuer ~]# ssh root@xx.xx.xx.xx 測試成功在掛載就不需要數據密碼