samba是在linux和unix系統上實現smb協議的乙個免費軟體,由伺服器及客戶端程式構成。smb(server messages block,資訊服務塊)是一種在區域網上共享檔案和印表機的一種通訊協議,它為區域網內的不同計算機之間提供檔案及印表機等資源的共享服務。
1.samba的作用
samba是一款軟體,主要提供cifs協議(基於檔案系統傳輸)
2.samba的安裝與啟用
環境:服務端:172.25.8.11 客戶端:172.25.8.10
(1)在服務端
yum install samba samba-client.x86_64 samba-common -y
systemctl start smb
systemctl stop firewalld.service
samba的基本資訊
主配置檔案: vim /etc/samba/smb.conf
埠:139/tcp 139/udp 445/tcp 445/udp
systemctl restart smb.service
vim /etc/samba/smb.conf
89 workgroup = westos ##工作組的設定
90 server string = hello world ##全域性共享資訊
91 hosts deny = 172.25.8.10 ##使用者黑名單
92 hosts allow = 172.25.8.11 ##使用者白名單
systemctl restart smb.service
測試 :客戶端 172.25.8.10
yum install smaba-client -y
smbclient -l ##沒有密碼直接回車 匿名登陸
黑名單開啟 客戶端無法訪問
把白名單開啟
本地使用者的建立
在服務端 172.25.8.11
samba使用者必須是本地使用者
useradd westos
useradd lee
smbpasswd -a westos
smbpasswd -a lee
pdbedit -l ##列出samba使用者
pdbedit -x lee ##刪除samba使用者
setsebool -p samba_enable_home_dirs on ###給家目錄許可權,/etc/samba/smb.conf的30行
測試 虛擬機器ip 172.25.8.10
smbclient -l -u westos ##輸入密碼
在smb下命令與linux不同,為了方便操作我們通常將其掛載後使用
mount /westos /mnt -o username=westos,password=westos
客戶端永久掛載
vim /etc/fstab
/westos /mnt cifs defaults,username=westos,password=westos 0 0
自定義共享目錄
mkdir /westos
semanage fcontext -a -t samba_share_t '/westos(/.*)?' ##開放當前目錄的selinux安全上下文
安全上下文檢視 ls -dz 目錄
restorecon -fvvr /westos/
vim /etc/samba/smb.conf
[data]
comment = westos ##描述
path = /westos ##共享目錄
systemctl restart smb
touch /westos/aa
測試效果 在客戶端 172.25.8.10
當目錄是系統目錄時
ip 172.25.8.11 服務端
vim /etc/samba/smb.conf
[system]
comment = file
path = /mnt
setsebool -p samba_export_all_ro on
systemctl restart smb.service
測試 客戶端 172.25.8.10
smbclient -l -u westos
匿名使用者登陸
vim /etc/samba/smb.conf
124 map to guest = bad user
321 [westos]
322 comment = westos
323 path = /westos
324 guest ok = yes ###匿名使用者可以登陸
systemctl restart smb
測試 ip:172.25.8.250
mount /mnt/ -o username=guest ##直接回車
df許可權控制
ip 172.25.8.11 服務端
chmod 777 /westos
setsebool -p samba_export_all_rw on
vim /etc/samba/smb.conf
writable = yes | no ###是否開啟寫許可權(開啟所有使用者都可以寫)
把上面的writable = yes | no注釋掉,在測試下面的情況
write list = westos ###給dream寫的許可權
write list = +westos ###給dream組寫的許可權
admin users = westos ###設定當前共享的root為dream
valid users = @westos ###設定當前共享的有效使用者組
browseable = yes | no ###當前共享是否隱藏
測試: ip 172.25.8.10 客戶端
mount /westos /mnt/ -o username=westos,password=westos
samba多使用者掛載
在客戶端 172.25.8.10
yum install cifs-utils.x86_64 -y
vim /root/sambapasswd
username=westos
password=westos
chmod 600 /root/sambapasswd
mount -o credentials=/root/sambapasswd,sec=ntlmssp,multiuser /westos /mnt/
Samba安裝使用
1.安裝 yum install samba 2.啟動 根據自己的系統選擇命令 service smb start 或者 systemctl restart smb.service 3.配置 etc samba 複製示例檔案 修改配置 新增訪問使用者 smbpasswd a user1 user1要...
安裝使用samba
sudo apt get install samba samba 檢視版本 cd etc samba lssudo cp smb.conf smb.conf.bak 複製配置檔案 mkdir share 在 home txdy827目錄下建立共享檔案 sudo chmod 777 share r c...
samba 安裝和使用
一 安裝 root localhost yum y install samba 二 配置 root localhost cd etc samba root localhost samba ll total 24 rw r r 1 root root 20 jul 9 12 40 lmhosts rw...