Samba 常用服务器搭建操作过程
生活随笔
收集整理的這篇文章主要介紹了
Samba 常用服务器搭建操作过程
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
同一網(wǎng)絡(luò)中既有 Windows 主機(jī)又有 Linux 主機(jī),為實(shí)現(xiàn)不同主機(jī)系統(tǒng)之間的資源共享,通常就是搭建 Samba 服務(wù)器
SMB 通信協(xié)議和 Samba 簡(jiǎn)介
-
SMB 協(xié)議
SMB是在局域網(wǎng)上共享文件和打印機(jī)的協(xié)議,為同一個(gè)網(wǎng)絡(luò)的 Windows 和 linux系統(tǒng)提供文件系統(tǒng),打印服務(wù) -
Samba簡(jiǎn)介
Samba包含一組軟件包,能讓 Linux 支持 SMB 協(xié)議,也是 Windows 能夠使 Linux 文件和打印機(jī)共享的基礎(chǔ);Samba是使用在類UNIX系統(tǒng)上運(yùn)行的服務(wù)器
SMB 簡(jiǎn)單服務(wù)器搭建
-
服務(wù)端配置
[root@shareserver ~] # yum install samba -y [root@shareserver ~] # yum install samba-client -y # 服務(wù)端安裝兩個(gè)包 [root@shareserver ~] # smbpasswd -a student # 給student添加登陸密碼,student必須在服務(wù)端本地存在 [root@shareserver ~] # touch /home/student/test # 創(chuàng)建測(cè)試文件test [root@shareserver ~] # pdbedit -L # 查看smba可登錄用戶列表 [root@shareserver ~] # pdbedit -x student # smba刪除student用戶登錄 -
客戶端配置
[root@shareserver ~] # yum install samba-client -y # 客戶端安裝包 [root@shareserver ~] # smbclient -L //192.168.1.152 # 匿名用戶查看共享資源 [root@shareserver ~] # smbclient -L //192.168.1.152 -U student # student用戶列表查看 [root@shareserver ~] # smbclient //192.168.1.152/student -U student # 直接登陸到服務(wù)端student用戶家目錄 [root@shareserver ~] # mount -o username=student,password=redhat //192.168.1.152/student /mnt # 掛載共享目錄 [root@shareserver ~] # ls /mnt # 查看掛載目錄 test # 測(cè)試文件存在,共享成功 [root@shareserver ~] # touch /mnt/file{1..3} # 客戶端在掛載目錄創(chuàng)建,也相當(dāng)于在服務(wù)端student家目錄同步更新
smba 權(quán)限等詳細(xì)配置
-
服務(wù)端詳細(xì)配置
[root@shareserver ~] # setenforce 0 # 內(nèi)核防火墻設(shè)置警告模式 [root@shareserver ~] # setsebool -P samba_enable_home_dirs on # 允許登陸家目錄 [root@shareserver ~] # vim /etc/samba/smb.conf # 主samba主配置文件 workgroup = WESTOS # 設(shè)置域名89行 hosts allow = 192.168.1.152 192.168.1.155 # 允許152和155主機(jī)登陸 hosts deny = 192.168.1.100 # 不允許100主機(jī)登陸## 共享自建目錄,更改安全上下文 [root@shareserver ~] # vim /etc/samba/smb.conf [linux] # 共享目錄名稱(隨意) comment = westos dir share # 目錄注釋信息 path = /westos # 寫入絕對(duì)路徑,必須屬實(shí)存在,此處共享的是服務(wù)端的/westos目錄 [root@shareserver ~] # semanage fcontext -a -t samba_share_t:s0 '/westos(/.*)?' # 遞歸更改安全上下文 [root@shareserver ~] # restorecon -RvvF westos # 同步刷新安全上下文 [root@client ~] # smbclient 192.168.1.152/linux -U student # 此時(shí)客戶端連接能看到該目錄內(nèi)容## 共享系統(tǒng)目錄,更改bool值 [root@shareserver ~] # vim /etc/samba/smb.conf [mnt] # 自定義目錄名mnt conmment = mnt dir share path = /mnt # 系統(tǒng)目錄/mnt [root@client ~] # smbclient 192.168.1.152/linux -U student # 此時(shí)連接還不能查看該目錄內(nèi)容 [root@shareserver ~] # setsebool -P samba_export_all_ro on # selinux開啟samba可讀所有目錄 [root@client ~] # smbclient 192.168.1.152/linux -U student # 此時(shí)再連接能查看該目錄內(nèi)容##共享目錄權(quán)限參數(shù) [root@shareserver ~] # chmod 777 student # 可暫時(shí)這樣改,但不建議 [root@shareserver ~] # vim /etc/samba/smb.conf [linux] comment = westos dir share path = /westos writable =yes # 所有人可寫 write list = @westos # westos組用戶可寫 valid users = + student # student組用戶有效 browseable = yes # 客戶端使用-L使是否可發(fā)現(xiàn)該設(shè)備 admin users = student # student用戶設(shè)置為超級(jí)用戶 create mask = 0644 # 上傳權(quán)限,加入該參數(shù)后,客戶端可上傳文件##匿名用戶登錄 guest ok = yes # windows匿名用戶可訪問 map to guest = bad user # 對(duì)guest的描述 (與 valid users = + student不能同時(shí)存在) -
客戶端安全控制機(jī)制
[root@client ~] # mount -o username=student,password=redhat //192.168.1.152/linux /mnt [root@client ~] # ls /mnt test # 掛載后,有顯示測(cè)試文件 [root@client ~] # su - westos [westos@client ~] # ls /mnt test # 更換用戶身份后,westos用戶也能看到服務(wù)端student的測(cè)試文件,說明安全性不足 -
samba多用戶掛載
[root@client ~] # yum install cifs-utils -y [root@client ~] # vim /root/smbpass # 編輯該文件,在其中指定本次掛載的用戶名密碼 username=student password=redhat [root@client ~] # chmod 600 /root/smbpass # 修改權(quán)限 [root@client ~] # mount -o credentials=/root/smbpass,sec=ntlmssp,multiuser //192.168.1.152/linux /mnt ##credentials=/root/smbpass # 本次掛載使用的用戶身份 ##sec=ntlmssp # 認(rèn)證方式 ##multiuser # 多用戶掛載 [root@client ~] # cd /mnt/ [root@client ~] # ls[root@client ~] # touch rootfile # root登陸的westos身份創(chuàng)建rootfile,在mnt中 [root@client ~] # ls # 此時(shí)客戶端登陸的westos身份可以看到rootfile [root@client ~] # ll # 此時(shí)用戶和組是1001,因?yàn)樵诜?wù)端的westos的uid是1001 [root@client ~] # su - student # [root@client ~] # ls /mnt/ # 會(huì)報(bào)permission denied,無權(quán)限,則到達(dá)限制未通過認(rèn)證用戶權(quán)力的目的[root@client ~] # su - student [root@client ~] # cifscreds add -u du 172.25.254.201 # student用戶驗(yàn)證為服務(wù)端的du用戶,uid是1002,然后輸入密碼 Password: #密碼輸入錯(cuò)誤后,需要清除 #cifscreds clearall #清除 #輸入正確密碼后,則當(dāng)前登陸smba的身份就是lee [root@client ~] # ls # 密碼正確后,此時(shí)可以看到mnt內(nèi)容 [root@client ~] # touch dufile [root@client ~] # ls -l # 會(huì)顯示dufile文件,且用戶和組id是1002
總結(jié)
以上是生活随笔為你收集整理的Samba 常用服务器搭建操作过程的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: eclipse的workset项目重复显
- 下一篇: Auto Layout详解