samba
- 1.samba簡介
- 2.samba監聽的端口
- 3.samb使用者
- samba安全級别
- samba配置檔案
- 執行個體
-
-
- 配置使用者認證共享:
- 配置匿名共享:
-
- RHCE題庫Samba服務:
-
-
- 示例中個别目錄名,密碼等,因個人習慣未完全按照題目要求,但做法沒有問題,請多見諒。
-
1.samba簡介
Samba是在Linux和UNIX系統上實作SMB協定的一個免費軟體,由伺服器及用戶端程式構成。
samba和nfs類似,也是在網絡中實作檔案共享的一種服務,但是nfs不支援Windows平台,而samb能夠在任何支援SMB協定的主機之間共享檔案的一種實作,當然也包括Windows。
2.samba監聽的端口
- TCP:139,445
- UDP:137,138
3.samb使用者
- 賬号:系統使用者/etc/passwd
- 密碼:Samba服務自有密碼檔案通過smbpasswd -a USERNAME指令設定
- //smbpasswd指令: -a Sys_User //添加系統使用者為samba使用者并為其設定密碼 -d //禁用使用者帳号 -e //啟用使用者帳号 -x //删除使用者帳号 [[email protected] ~]# yum -y install samba-* [[email protected] ~]# useradd bebejo [[email protected] ~]# sambapasswd -a bebejo [[email protected] ~]# smbpasswd -a bebejo New SMB password: Retype new SMB password: Added user bebejo.
samba安全級别
- user: 基于本地的驗證
- server: 由另一台指定的伺服器對使用者身份進行認證
- domain: 由域控進行身份驗證
samba配置檔案
/etc/samba/smb.conf(主配置檔案)
- [global] 全局配置,此處的設定項對整個samba伺服器都有效
-
[homes] 宿主目錄共享設定,此處用來設定Linux使用者的預設共享,對應使用者的宿主目錄。
當使用者通路伺服器中與自己使用者名同名的共享目錄時,通過驗證後将會自動映射到該使用者的宿主目錄中
- [printers] 列印機共享設定
執行個體
配置使用者認證共享:
//使用yum指令安裝samba伺服器:
[[email protected] ~]# yum -y install samba-*
//映射共享目錄:
//建立使用者bebejo:
[[email protected] ~]# useradd -M bebejo
//為bebejo使用者建立smb共享密碼:
[[email protected] ~]# smbpasswd -a bebejo
New SMB password:
Retype new SMB password:
Added user bebejo.
//假設這裡映射bebejo使用者為nmsl使用者,那麼就要在/etc/samba/smbusers檔案中添加如下内容:
[[email protected] ~]# cat /etc/samba/smbusers
bebejo = nmsl
//在全局配置中添加如下内容:
[global]
workgroup = SAMBA
security = user
username map = /etc/samba/smbusers //添加此行内容
//建立一個共享目錄bebejo
[[email protected] ~]# mkdir /opt/bebejo
[[email protected] ~]# chown -R bebejo.bebejo /opt/bebejo
[[email protected] ~]#chmod 777 /opt/bebejo
[[email protected] ~]# cd /opt
[[email protected] opt]# ll
drwxrwxrwx. 2 bebejo bebejo 6 1月 15 07:13 bebejo
//配置共享
[[email protected] opt]# vim /etc/samba/smb.conf
[bebejo]
comment = bebejo
path = /opt/bebejo
browsable = yes
guest ok = yes
writable = yes
write list = nmsl
public = yes
//啟動、重新開機、重新加載、開機自動啟動
[[email protected] ~]# systemctl start smb
[[email protected] ~]# systemctl restart smb
[[email protected] ~]# systemctl reload smb
[[email protected] ~]# systemctl enable smb
//在客戶機檢視samba伺服器有哪些共享資源
[[email protected] ~]# smbclient -L 192.168.157.33 -U nmsl
Enter SAMBA\nmsl's password:
Domain=[XAII-SERVER] OS=[Windows 6.1] Server=[Samba 4.6.2]
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
bebejo Disk bebejo
IPC$ IPC IPC Service (Samba 4.6.2)
Domain=[XAII-SERVER] OS=[Windows 6.1] Server=[Samba 4.6.2]
Server Comment
--------- -------
Workgroup Master
--------- -------
SAMBA XAII33
//将samba伺服器的共享資源wangqing挂載到客戶機本地
[[email protected] ~]# mount -t cifs //192.168.157.33/bebejo /opt/smb -o username=nmsl,password=cheers
[[email protected] ~]# df -h
檔案系統 容量 已用 可用 已用% 挂載點
/dev/mapper/rhel-root 17G 1.1G 16G 7% /
devtmpfs 901M 0 901M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 8.5M 904M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 1014M 143M 872M 15% /boot
tmpfs 183M 0 183M 0% /run/user/0
/dev/loop0 3.8G 3.8G 0 100% /mnt
//192.168.157.33/bebejo 17G 1.4G 16G 8% /opt/smb
//在客戶機上進入共享目錄建立新檔案
[[email protected] smb]# touch bebejo
[[email protected] smb]# ll
-rw-r--r-- 1 runtime01 runtime01 0 1月 15 18:23 bebejo
//在windows上驗證:
//在服務端驗證
[[email protected] opt]# cd bebejo/
[[email protected] bebejo]# ll
-rw-r--r--. 1 bebejo bebejo 0 1月 15 07:23 bebejo
drwxr-xr-x. 2 xaii xaii 6 1月 15 07:45 我來了
配置匿名共享:
//建立smb使用者
[[email protected] ~]# useradd -M messi
[[email protected] ~]# smbpasswd -a messi
New SMB password:
Retype new SMB password:
Added user messi.
//在全局配置中添加如下内容:
[global]
workgroup = SAMBA
security = user
map to guest = Bad User //添加此行内容
//建立共享目錄messi
[[email protected] ~]# mkdir /opt/messi
[[email protected] ~]# chmod 777 /opt/messi
[[email protected] ~]# ll /opt
drwxrwxrwx. 2 root root 6 1月 15 07:27 messi
//配置共享
[[email protected] ~]# vim /etc/samba/smb.conf
[messi]
comment = messi
path = /opt/messi
browsable = yes
guest ok = yes
writable = yes
public = yes
//啟動smb服務:
[[email protected] ~]# systemctl start smb
//在客戶機檢視samba伺服器有哪些共享資源
[[email protected] ~]# smbclient -L 192.168.157.33 -U 'Bad User'
Enter SAMBA\Bad User's password:
OS=[Windows 6.1] Server=[Samba 4.6.2]
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
bebejo Disk bebejo
IPC$ IPC IPC Service (Samba 4.6.2)
messi Disk messi
OS=[Windows 6.1] Server=[Samba 4.6.2]
Server Comment
--------- -------
Workgroup Master
--------- -------
SAMBA XAII33
//将samba伺服器的共享資源wangqing挂載到客戶機本地
[[email protected] ~]# mount -t cifs //192.168.157.33/messi /opt/samba -o username='Bad User'
[[email protected] ~]# df -Th
檔案系統 類型 容量 已用 可用 已用% 挂載點
/dev/mapper/rhel-root xfs 17G 1.1G 16G 7% /
devtmpfs devtmpfs 901M 0 901M 0% /dev
tmpfs tmpfs 912M 0 912M 0% /dev/shm
tmpfs tmpfs 912M 8.5M 904M 1% /run
tmpfs tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 143M 872M 15% /boot
tmpfs tmpfs 183M 0 183M 0% /run/user/0
/dev/loop0 iso9660 3.8G 3.8G 0 100% /mnt
//192.168.157.33/messi cifs 17G 1.4G 16G 8% /opt/samba
//在客戶機上進入共享目錄建立新檔案
[[email protected] ~]# cd /opt/samba/
[[email protected] samba]# ls
[[email protected] samba]# touch wolaile
[[email protected] samba]# ll
-rw-r--r-- 1 nobody nobody 0 1月 15 18:38 wolaile
//在windows上驗證
//在服務端驗證
[[email protected] ~]# cd /opt/messi/
[[email protected] messi]# ll
-rw-r--r--. 1 nobody nobody 0 1月 15 07:38 wolaile
drwxr-xr-x. 2 xaii xaii 6 1月 15 07:43 我又來了
RHCE題庫Samba服務:
//修改工作組
[[email protected] ~]# cat /etc/samba/smb.conf|grep workgroup
workgroup = STAFF
//建立共享目錄
[[email protected] ~]# mkdir /common
[[email protected] ~]# tail -4 /etc/samba/smb.conf
[common]
path = /common
browsable = yes
//添加natasha使用者
[[email protected] ~]# useradd -M natasha
[[email protected] ~]# smbpasswd -a natasha
New SMB password:
Retype new SMB password:
Added user natasha.
//給natasha使用者設定acl
[[email protected] ~]# setfacl -m u:natasha:r-x /common
//設定防火牆
[[email protected] ~]# firewall-cmd --add-rich-rule 'rule family=ipv4 source address=192.168.157.0/24 service name=samba accept' --permanent
success
[[email protected] ~]# firewall-cmd --add-rich-rule 'rule family=ipv4 source address=192.168.157.0/24 service name=samba-client accept' --permanent
success
[[email protected] ~]# setsebool -P samba_enable_home_dirs on
[[email protected] ~]# chcon -Rt samba_share_t /common
//重載防火牆,重新開機samba服務
[[email protected] /]# firewall-cmd --reload
success
[[email protected] /]# systemctl restart smb
[[email protected] /]# systemctl reload smb
//在用戶端進行挂載
[[email protected] ~]# mount -t cifs //192.168.157.33/common /rhce -o username=natasha,password=cheers
[[email protected] ~]# df -h
檔案系統 容量 已用 可用 已用% 挂載點
//192.168.157.33/common 17G 1.4G 16G 8% /rhce
//步驟同十三 題
[[email protected] ~]# mkdir /storage
[[email protected] ~]# chcon -Rt samba_share_t /storage/
[[email protected] ~]# vim /etc/samba/smb.conf
[[email protected] ~]# tail -3 /etc/samba/smb.conf
[storage]
path = /storage
browsable = yes
//建立使用者
[[email protected] ~]# useradd -M sarah
[[email protected] ~]# useradd -M kitty
[[email protected] ~]# smbpasswd -a sarah
New SMB password:
Retype new SMB password:
Added user sarah.
[[email protected] ~]# smbpasswd -a kitty
New SMB password:
Retype new SMB password:
Added user kitty.
//設定facl
[[email protected] ~]# setfacl -m u:sarah:r-x /storage/
[[email protected] ~]# setfacl -m u:kitty:rwx /storage/
//添加有效使用者
[[email protected] ~]# tail -6 /etc/samba/smb.conf
[share]
path = /storage
browsable = yes
valid users = sarah,kitty
writable = no
write list = kitty
//重新開機服務
[[email protected] ~]# systemctl restart smb
//用戶端驗證
[[email protected] ~]# mount -a
[[email protected] ~]# cat /etc/fstab
//192.168.157.33/share /rhce_2 cifs multiuser,username=sarah,password=cheers,sec=ntlmssp 0 0
[[email protected] ~]# df -h
//192.168.157.33/share 17G 1.4G 16G 8% /rhce_2
//需要在用戶端切換至一個普通使用者來驗證
[[email protected] ~]# yum -y install cifs-utils*
[[email protected] ~]# su - runtime01
上一次登入:六 1月 12 02:44:25 CST 2019pts/0 上
[[email protected] ~]$ cifscreds add -u kitty 192.168.157.33
Password: //kitty使用者的密碼
[[email protected] ~]$ df -h //隻要沒報錯就是切換成功
//已經可以進入挂載點建立檔案了
[[email protected] ~]$ cd /rhce_2
[[email protected] rhce_2]$ touch aa
[[email protected] rhce_2]$ ll
總用量 0
-rw-r--r-- 1 runtime05 runtime05 0 1月 16 01:40 aa