当我们需要管理一台远程的linux服务器的时候经常使用的是比较安全的ssh。以下是通过ssh挂在远程目录的方法:
1)临时挂载
在本地主机上执行:
sudo vim /etc/fuse.conf
在/etc/fuse.conf中添加user_allow_other。
sshfs 远端用户名@远端IP:远端目录 本地挂载目录 -o allow_other
若提示一下错误,安装sshfs服务:
fusermount: option allow_other only allowed if 'user_allow_other' is set in /etc/fuse.conf sudo apt-get install sshfs fuse -y
示例:
sudo sshfs svr@192.168.200.175:/home/jingbo/work /home/work -o allow_other -o reconnect -o nonempty
2)永久挂载
如需自动挂载,可以在/etc/fstab中添加如下代码:
sshfs username@ipaddress:/remotepath ~/remoteserv fuse user,_netdev,exec,reconnect,uid=1000,gid=1000,idmap=user,allow_other 0 0
如果挂载没有效果,可以查看日志,sshd的日志在:/var/log/auth.log:
Aug 8 11:05:21 localhost sshd[21595]: Authentication refused: bad ownership or modes for directory /remotepath
此时一般是remotepath目录的权限错误,一般该目录的权限应为700或755,不能为77x。
3)卸载
fusemount –u 本地挂载点 # /home/jingbo/remote
4)设置开机自动挂载
sudo -S sshfs -o ssh_command='sshpass -p 123 ssh' svr@192.168.1.200:/home/data/datasets /home/data/datasets -o allow_other -o reconnect -o nonempty << EOF 1 EOF
大家都知道登陆ssh可以用sshpass自动输入密码,但是挂载sshfs却不行,其实sshpss是可以给sshfs输入密码的,只需要使用参数-o ssh_command=’sshpass -p password ssh’。
例如:
sshfs -o ssh_command='sshpass -p 123456 ssh' -o cache=yes,allow_other user@ip path
[work] sshfs挂载时自动输入密码_This is bill的专属博客-CSDN博客
参考:
Ubuntu 下使用 sshfs 挂载远程目录到本地 - Cyril_Wu - 博客园



