server虛擬機
yum install samba samba-client.x86_64 samba-common -y
systemctl start smb
systemctl enable smb
systemctl stop firewalld
systemctl disable firewalld
useradd 123
useradd 124
smbpasswd -a 123
smbpasswd -a 124
pdbedit -L
pdbedit -x 124
pdbedit -L
getsebool -a | grep samba setsebool -P samba_enable_home_dirs on
desktop虛擬機
yum install samba-client.x86_64 -y
smbclient -L //172.25.15.11
smbclient //172.25.15.11/123 -U 123
server虛擬機
mkdir /samba
touch /samba/file{1..3}
vim /etc/samba/smb.conf
[WESTOS]
comment = /samba dir
path = /samba
[ETC]
comment = etc
path = /mnt
systemctl restart smb
semanage fcontext -a -t samba_share_t '/samba(/.*)?'
restorecon -FvvR /samba/
setsebool -P samba_export_all_ro on
desktop虛擬機
smbclient //172.25.15.11/WESTOS -U 123
smbclient //172.25.15.11/ETC -U 123
匿名
server虛擬機
vim /etc/samba/smb.conf
map to guest = bad user #125行
guest ok = yes #328行
systemctl restart smb
desktop虛擬機
smbclient //172.25.15.11/WESTOS
更改Domain
server虛擬機
vim /etc/samba/smb.conf
workgroup = XXX #89行
systemctl restart smb
desktop虛擬機
mount //172.25.15.11/WESTOS /mnt -o username=123,password=123
此時不能創建文件
server虛擬機
vim /etc/samba/smb.conf
writeable = yes #329行
systemctl restart smb
vim /etc/samba/smb.conf
刪除上一步輸入的329行
write list = +123 #是否可寫 +或@表示組 #從329行開始
browseable = yes #是否可以通過smbclient -L //172.25.15.11列出
valid users = 123 #指定有效用戶
admin users = 123 #提升用戶權限,在共享文件夾權限爲755時,使123用戶可以進行操作
systemctl restart smb smaba
多用戶掛載
預期目的
當在desktop端掛載了samba共享之後,可以通過/root/sambauserfile中的密碼進行認證。但是只有在samba服務器中存在的用戶纔可以訪問
server虛擬機
vim /etc/samba/smb.conf
[WESTOS]
comment = lalala
path = /smaba
browseable = yes
writeable = yes
systemctl restart smb #禁止匿名用戶,取消提升用戶權限以及有效用戶的指定
desktop虛擬機
useradd 123 #建立和服務器端一樣的用戶
vim /root/sambauserfile
username=123
password=123 #爲掛載提供一個用戶,如果文件中用戶在samba服務器中不存在,則無法掛載
yum install cifs-utils -y #認證所需軟件
mount //172.25.15.11/WESTOS /mnt -o credentials=/root/sambauserfile,multiuser,sec=ntlmssp
su - XXX #切換不同用戶進行實驗
cifscreds add 172.25.15.11 #認證