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