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目錄的權限錯誤,一般該目錄的權限應爲700或755,不能爲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
是服務端的服務沒有啓動,重新啓動服務即可。