Centos7.3部署Samba共享服務

Samba是在Linux和UNIX系統上實現SMB協議的一個免費軟件,由服務器及客戶端程序構成,
SMB(Server Messages Block,信息服務塊)是一種在局域網上共享文件和打印機的一種通信協議,它爲局域網內的不同計算機之間提供文件及打印機等資源的共享服務;SMB協議是客戶機/服務器型協議,客戶機通過該協議可以訪問服務器上的共享文件系統、打印機及其他資源。通過設置“NetBIOS over TCP/IP”使得Samba不但能與局域網絡主機分享資源,還能與全世界的電腦分享資源。Samba服務器監聽端口爲UDP的137和138,TCP的139和445,那就需要在本地防火牆允許這些端口訪問。


實驗環境:單臺服務器部署,IP地址爲:192.168.10.30
模擬公司共享服務器---創建CS部門和HR部門,並再建個共享文件夾

[root@server ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

[root@samba ~]# yum install samba samba-client samba-common -y
[root@samba ~]# cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
[root@samba ~]# egrep -v "#|^$" /etc/samba/smb.conf.bak |grep -v "^;" >/etc/samba/smb.conf
[root@samba ~]# vim /etc/samba/smb.conf //查看smb.conf配置文件

[global]
workgroup = WORKGROUP //定義工作組,也就是windows中的工作組概念
server string = Samba Server Version %v //定義Samba服務器的簡要說明
log file = /var/log/samba/log.%m //定義Samba用戶的日誌文件,%m代表客戶端主機名
max log size = 50
security = user
passdb backend = tdbsam
load printers = yes
cups options = raw
[homes]
comment = Home Directories
browseable = no
writable = yes
[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
guest ok = no
writable = no
printable = yes
[HR]
comment = This is a directory of HR.
path = /root/install/HR/
public = no
admin users = hradmin
valid users = @hr_department
writable = yes
create mask = 0750
directory mask = 0750
[CS]
comment = This is a directory of CS.
path = /root/install/CS/
public = no
admin users = csadmin
valid users = @cs_department
writable = yes
create mask = 0750
directory mask = 0750
[Share]
comment = This is a Share directory.
path = /root/install/Share/
public = no
valid users = @hr_department, @cs_department
writable = yes
create mask = 0750
directory mask = 0750

[root@samba ~]# systemctl enable smb && systemctl start smb
[root@samba ~]# groupadd hr_department
[root@samba ~]# useradd -g hr_department -s /sbin/nologin hradmin
[root@samba ~]# useradd -g hr_department -s /sbin/nologin hruser
[root@samba ~]# smbpasswd -a hradmin

New SMB password:hello123
Retype new SMB password:hello123

[root@samba ~]# smbpasswd -a hruser

New SMB password:hello123
Retype new SMB password:hello123

[root@samba ~]# groupadd cs_department
[root@samba ~]# useradd -g cs_department -s /sbin/nologin csadmin
[root@samba ~]# useradd -g cs_department -s /sbin/nologin csuser
[root@samba ~]# smbpasswd -a csadmin

New SMB password:hello123
Retype new SMB password:hello123

[root@samba ~]# smbpasswd -a csuser

New SMB password:hello123
Retype new SMB password:hello123

[root@samba ~]# mkdir -p /root/install/{HR,CS,Share}
[root@samba ~]# chown hradmin.hr_department /root/install/HR
[root@samba ~]# chown csadmin.cs_department /root/install/CS
[root@samba ~]# chmod -R 755 /root/install/


在CMD命令行裏面訪問方式爲:\\192.168.10.30 (SMB文件共享服務端IP),如果沒有權限訪問,需要注意防火牆和selinux設置
Centos7.3部署Samba共享服務

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章