栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

ubuntu下挂载远程目录

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ubuntu下挂载远程目录

        当我们需要管理一台远程的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 - 博客园

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/361532.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号