1、smb文件共享linux
yum install samba samba-common samba-client-y systemctl start smb nmb systemctl enable smb nmb
smb用戶必須時本地用戶 smbpasswd -a student New SMB password: #輸入smb當前用戶密碼 Retype new SMB password: #確認密碼 pdbedit -L #查看smb用戶信息 pdbedit -x smb用戶 #刪除smb用戶
查看本身的共享目錄,添加目錄後默認共享家目錄vim
[root@server ~]# smbclient -L //172.25.254.231 -U student Enter student's password: Domain=[MYGROUP] OS=[Windows 6.1]Server=[Samba 4.2.3] Sharename Type Comment --------- ---- ------- IPC$ IPC IPC Service (Samba Server Version 4.2.3) student Disk Home Directories Domain=[MYGROUP] OS=[Windows 6.1]Server=[Samba 4.2.3] Server Comment --------- ------- Workgroup Master --------- -------
[root@server ~]# smbclient //172.25.254.231/student -U student Enter student's password: Domain=[MYGROUP] OS=[Windows 6.1]Server=[Samba 4.2.3] smb: \> #此時你若是想看你的共享目錄就會出現以下錯誤,由於的selinux 開着 smb: \> ls NT_STATUS_ACCESS_DENIED listing \* #這時你須要將selinux的samba_enable_home_dirs打開。 #同時還須要在配置文件中設定smb用戶能夠訪問本身的家目錄 #就是/etc/samba/smb.conf中第30行 setsebool -P samba_enable_home_dirs on [root@server ~]#setsebool samba_enable_home_dirs on [root@server ~]# smbclient //172.25.254.231/student -U student Enter student's password: Domain=[MYGROUP] OS=[Windows 6.1]Server=[Samba 4.2.3] smb: \> ls . D 0 Thu Jul 10 19:06:52 2014 .. D 0 Thu Jul 10 18:19:09 2014 .bash_logout H 18 Wed Jan 29 07:45:18 2014 .bash_profile H 193 Wed Jan 29 07:45:18 2014 .bashrc H 231 Wed Jan 29 07:45:18 2014 .ssh DH 0 Thu Jul 10 18:19:10 2014 .config DH 0 Thu Jul 10 19:06:53 2014 10473900 blocks of size 1024. 7318236 blocksavailable
[root@server ~]# vim /etc/samba/smb.conf 30 setsebool -P samba_enable_home_dirs on #開啓能夠查看用戶的家目錄 49 setsebool -P samba_export_all_roon #只讀共享 51 setsebool -P samba_export_all_rwon #讀寫共享 ##在selinux中設定smb用戶能夠訪問本身的家目錄 89 workgroup = MYGROUP #修改標籤名稱也就是下面的Domai的名稱 #[root@server ~]# smbclient -L //172.25.254.231 -U student #Enter student's password: #Domain=[MYGROUP] OS=[Windows 6.1]Server=[Samba 4.2.3] 96 hosts allow =172.25.254.131 #只給172.25.254.131這個主機,其餘用戶遠程登錄時會出下以下錯誤: [root@server ~]# smbclient //172.25.254.231/student -U student Enter student's password: protocol negotiation failed:NT_STATUS_INVALID_NETWORK_RESPONSE
3.1共享目錄的簡單設定步驟安全
vim /etc/samba/smb.conf [haha] 共享名稱 comment = 對共享目錄的描述 path = 共享目錄的絕對路徑 workgroup = WESTOS 當共享目錄爲用戶自創建目錄時 semanage fcontext -a -t samba_share_t '目錄名稱(/.*)?' restorecon -RvvF 目錄名稱 當共享目錄爲系統創建目錄 setsebool -P samba_export_all_ro on #只讀共享 setsebool -P samba_export_all_rw on #讀寫共享
3.2共享目錄的實例bash
[root@server ~]# vim /etc/samba/smb.conf #下面爲添加的共享目錄的代碼 [feitian] #共享目錄的名稱,就是你掛載時須要填寫的:例如//172.25.254.231/feitian comment = local directory /westos path = /westos [root@server ~]# systemctl restart smb #這時你在查看就會多了一個共享目錄當你登錄時會發現登錄以後,出現以下錯誤,仍是由於selinux [root@server ~]# smbclient -L //172.25.254.231 -U student feitian Disk local directory /westos [root@server westos]# smbclient //172.25.254.231/feitian -U student Enter student's password: #輸入添加的用戶student的密碼 Domain=[MYGROUP] OS=[Windows 6.1]Server=[Samba 4.2.3] smb: \> ls NT_STATUS_ACCESS_DENIED listing \* #修改smb共享目錄的安全上下文 [root@server ~]# semanage fcontext -a -t samba_share_t '/westos(/.*)?' [root@server ~]# restorecon -RvvF /westos restorecon reset /westos contextunconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0 restorecon reset /westos/file1 contextunconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0 restorecon reset /westos/file2 contextunconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0 restorecon reset /westos/file3 contextunconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0 #這時你登錄就會好了,別忘了/etc/samba/smb.conf中selinux須要打開。還要在主機上開啓selinux對smb服務的只讀或者讀寫權限。 [root@client ~]# mount//172.25.254.231/student /mnt -o username=student,password=student [root@client ~]# df -h |grep//172.25.254.231 //172.25.254.231/student 10G 3.1G 7.0G 31% /mnt #開機自動掛載 vim /etc/fstab //172.25.254.231/feitian /mnt cifs defaults,username=studnet,password 0 0
#匿名用戶訪問 guest ok = yes map to guest = bad user #訪問控制 hosts allow = #僅容許 hosts deny = #僅拒絕 valid users = #當前共享的有效用戶 valid users = westos #當前共享的有效用戶爲westos valid users = @westos #當前共享的有效用戶爲westos組 valid users = +westos #當前共享的有效用戶爲westos組 #讀寫控制 全部用戶都可寫 chmod o+w /mnt setsebool -P samba_export_all_rw on vim /etc/samba/smb.conf writable = yes #設定指定用戶可寫 write list = student #可寫用戶 write list = +student #可寫用戶組 write list = @student #也是可寫用戶組 admin users = westos #共享的超級用戶指定
在客戶端作以下操做
服務器
[root@client ~]# vim /root/haha username=student password=student [root@client ~]# chmod 600 /root/haha [root@client ~]# yum install cifs-utils -y [root@client ~]# cifscreds clear -u student 172.25.254.231 Password: ##smb用戶student的密碼 mount -o credentials=/root/haha,multiuser,sec=ntlmssp //172.25.254.231/haha /mnt/ #credentials=/root/haha 指定掛載時所用到的用戶文件 #multiuser 支持多用戶認證 #sec=ntlmssp 認證方式爲標準smb認證方式 [root@client ~]# df -h|grep 172.25.254.231 //172.25.254.231/feitian 10G 3.1G 7.0G 31% /mnt #共享用戶 cifscreds add -u westos 172.25.254.100 Password: ##smb用戶westos的密碼 ls /mnt
二 、NFS 文件共享網絡
一、NFS介紹ssh
NFS是Network File System 的縮寫,主要功能是經過網絡讓不一樣的機器彼此之間共享文件或目錄,能夠經過掛載(mount)的方式將NFS服務器端共享的數據文件目錄掛載到NFS客戶端本地中。NFS協議有多個版本:Linux支持版本四、版本3和版本2,而大多數系統管理員熟悉的是NFSv3。默認狀況下,該協議並不安全,可是更新的版本(如NFSv4)提供了更安全的身份驗證支持,甚至能夠經過kerberos進行加密ide
二、簡單的NFS不一樣主機之間的共享加密
在server上的簡但配置spa
[root@nfs-clinent ~]# vim /etc/exports /westso/lala 172.25.254.231(rw,sync) #共享serve /westos/lala這個目錄,客戶端有讀和寫還有在共享目錄的創建刪除會直接寫入主機的內存中 #exportfs -rv 直接刷新,不用重啓NFS服務
在client的簡但配置
[root@nfs-clinent ~]# showmount -e 172.25.254.231 Export list for 172.25.254.231: /westos/lala 172.25.254.131 [root@nfs-clinent ~]# mount -t nfs 172.25.254.231:/westos /mnt [root@nfs-clinent ~]# df -h|gerp 172.25.254.231 172.25.254.231:/westos/lala 9.2G 2.5G 6.3G 29% /mnt
設置開機自動掛載,這裏就不在說了,已經說太多變了
三、默認目錄自動掛載
3.1 安裝軟件
客戶端安裝軟件
[root@nfs-clinent ~]# yum install autofs -y [root@nfs-clinent ~]# systemctl restart autifs.server [root@nfs-clinent ~]# cd /net [root@nfs-clinent ~]# cd 172.25.254.231 [root@nfs-clinent ~]# ls westos [root@nfs-clinent ~]# cd /westos/lala #這樣就能夠看到他的共享目錄下面的內容,並且是自動掛載,退出目錄後默認5分鐘自動卸載。他能夠修改 #在/etc/autofs.conf中能夠修改。
四、 指定目錄的自動掛載
在客戶端修改配置文件
[root@nfs-clinent ~]# vim /etc/auto.master #添加一行,/nfs是指共享目錄的第一層目錄,/etc/auto.nfs他是master的子文件 /westos /etc/auto.nfs [root@nfs-clinent ~]#vim /etc/auto.nfs #共享目錄的第二層目錄 * 172.25.254.231:/& #這個意思是前面的第二層目錄和第一層目錄是一致的,若是你掛載了lala就表示你 自動掛載的目錄爲/westos/lala