Ubuntu下挂载远程目录方法

1.ssh

当我们需要管理一台远程的linux服务器的时候经常使用的是比较安全的ssh。
以下是通过ssh挂在远程目录的方法:

 :~$  sudo apt-get install sshfs fuse
 :~$  sshfs <username>@<ipaddress>:/remotepath ~/remoteserv -o allow_other
若提示一下错误:
fusermount: option allow_other only allowed if 'user_allow_other' is set in /etc/fuse.conf
则在/etc/fuse.conf中添加user_allow_other

如需自动挂载,可以在/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目录的权限错误,一般该目录的权限应为700755,不能为77x。

2.nfs

服务器端: 172.21.10.68

:~$   sudo apt-get install nfs-kernel-server  portmap //安装nfs portmap
:~$   sudo vi /etc/exports                            //配置nfs
# /etc/exports: the access control list for filesystems which may be exported
#               to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
#Add Next Line //feison
/home/feison/nfs *(rw,sync,no_root_squash,no_subtree_check) 
:wq
:~$   sudo service nfs restart                       //启动nfs服务
:~$   sudo service portmap start           //启动portmap服务

客户端:

:~$   sudo apt-get install nfs-kernel-server
:~$   sudo mount -t nfs 172.21.10.68:/home/feison/nfs  ./nfs
:~$   sudo umount ./nfs
如果出现:mount: mount to NFS server 'p470-1' failed: RPC Error: Program not registered
是服务端的服务没有启动,重新启动服务即可。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章