yum -y install samba # 查看yum源中Samba版本 yum list | grep samba # 查看samba的安裝狀況 rpm -qa | grep samba
Samba服務器安裝完以後, 會生成配置文件目錄/etc/samba, /etc/samba/smb.conf是samba的核心配置文件.windows
Samba服務安裝完成以後有兩種方法啓動:bash
service smb start/stop/restart/status # 或者 systemctl start/stop/restart/status smb.service # 設置smb服務開機啓動 systemctl enable smb.service
3. 開放Samba服務使用到的端口號服務器
Samba服務會用到以下的一些端口號:tcp
若是不想關閉防火牆的話, 就要在CentOS中放開Samba使用到的TCP端口號測試
firewall-cmd --zone=public -add-port=139/tcp --permanent firewall-cmd --zone=public -add-port=389/tcp --permanent firewall-cmd --zone=public -add-port=445/tcp --permanent firewall-cmd --zone=public -add-port=901/tcp --permanent firewall-cmd --reload # 查看已經放開的端口號 firewall-cmd --list-all
4. 配置Samba服務spa
mkdir /opt/shares
# 由於須要設置匿名用戶能夠上傳下載文件, 因此須要給shares目錄授予nobody權限 chown -R nobody:nobody /opt/shares
cp /etc/samba/smb.conf /etc/samba/smb.conf.bak vi /etc/samba/smb.conf
修改配置以下:rest
# See smb.conf.example for a more detailed config file or # read the smb.conf manpage. # Run 'testparm' to verify the config is correct after # you modified it. [global] workgroup = SAMBA security = user map to guest = Bad User log file = /var/log/samba/log.%m [public] comment = Public Stuff path = /opt/shares public = yes read only = No
其中 path就是上邊設置的共享目錄, read only 表示是否有寫權限code
systemctl restart smb.service
# 使用testparm命令
testparm
設置共享目錄, 只容許指定用戶組的用戶訪問blog
groupadd cnki # useradd -g 組名 用戶名 useradd -g cnki share # 設置用戶share的密碼 passwd share #刪除用戶 userdel -r 用戶名
光添加系統帳戶還不夠, 須要把已經存在的系統帳戶添加到samba中才能夠訪問共享目錄cmd
# smbpasswd 參數: -a: 添加 -x: 刪除 -d: 禁用 -e: 啓用
smbpasswd -a share
mkdir /opt/shares1 # chown -R 用戶名:組名 目錄 chown -R share:cnki /opt/shares1
修改配置文件/etc/samba/smb.conf以下
# See smb.conf.example for a more detailed config file or # read the smb.conf manpage. # Run 'testparm' to verify the config is correct after # you modified it. [global] workgroup = SAMBA security = user map to guest = Bad User log file = /var/log/samba/log.%m [shares] comment = CNKI path = /opt/shares1 # 表示用戶組 valid users = @cnki read only = No
systemctl restart smb.service
# 檢查smb.conf文件是否配置正確
testparm