安裝
安裝
sudo apt install samba
檢查服務(wù)狀態(tài)
systemctl status smbd --no-pager -l
檢查是否啟用(開機(jī)自啟動(dòng))
systemctl is-enabled smbd
# enable it if inactive
systemctl enable smbd
配置
(可選)添加用戶
sudo usermod -aG sambashare [username]
設(shè)置密碼
sudo smbpasswd -a [username]
創(chuàng)建公開共享(可匿名訪問)
sudo vi /etc/samba/smb.conf
按以下格式創(chuàng)建內(nèi)容
[public]
comment = public anonymous access
path = /data/
browsable =yes
create mask = 0660
directory mask = 0771
writable = yes
guest ok = yes
說明:
-
[public]
方括號(hào)內(nèi)為share后顯示的目錄名 -
path = /data/
為用于share的本地路徑 -
browsable =yes
是否可以瀏覽 create mask = 0660
directory mask = 0771
-
writable = yes
是否可寫 -
guest ok = yes
是否允許匿名訪問
開啟 SMB1
對(duì)于很多電視盒子, 運(yùn)行安卓或CoreElEC, 只支持 SMB1, 連接默認(rèn)配置的 Samba 服務(wù)會(huì)直接報(bào) Timeout, 需要開啟 smbd 服務(wù)對(duì) SMB1 的支持
編輯 /etc/samba/smb.conf, 在[global]
下添加
## Enable SMB1 ##
server min protocol = NT1
重啟 smbd 后, 電視盒就可以連接了.
配置項(xiàng)
Samba可以配置的屬性可以參考 https://www.samba.org/samba/docs/using_samba/ch08.html
create mask
八進(jìn)制數(shù), 每個(gè)數(shù) 3-bit 代表一組權(quán)限[rwx], 整個(gè)mask 代表 smb 客戶端在創(chuàng)建文件時(shí)可以設(shè)置哪些bit.
默認(rèn)是 0744, 對(duì)應(yīng)[--- rwx r-- r--] 這代表著 unix 下的文件所有者可以 rwx [讀,寫,執(zhí)行], 同組用戶和其它可以 r [讀]
對(duì)于下面的例子, create mask 限制從 smb 創(chuàng)建文件/目錄時(shí), 不管來(lái)自于什么客戶端, 文件和目錄的最大權(quán)限為 744
[data]
path = /home/samba/data
browseable = yes
guest ok = yes
writeable = yes
create mask = 744
If you need to change it for nonexecutable files, we recommend 0644, or rw-r--r--.
Keep in mind that the execute bits can be used by the server to map certain DOS file attributes, as described earlier. If you're altering the create mask, those bits have to be part of the create mask as well.
directory mask
與create mask 相同, 八進(jìn)制數(shù), 每個(gè)數(shù) 3-bit 代表一組權(quán)限[rwx], 整個(gè)mask 代表 smb 客戶端在創(chuàng)建目錄時(shí)可以設(shè)置哪些bit.
默認(rèn)是0744, 對(duì)應(yīng) [--- rwx r-- r--], 允許所有用戶讀, 但是只允許所有者自己瀏覽和修改. 建議改為 0750, [--- rwx r-x ---], 避免所有人可以訪問
下面的例子中, 從客戶端創(chuàng)建的目錄, 最大權(quán)限為 755
[data]
path = /home/samba/data
browseable = yes
guest ok = yes
writeable = yes
directory mask = 755
force create mode
這個(gè)配置項(xiàng)用于 當(dāng)文件權(quán)限發(fā)生變化時(shí)強(qiáng)制設(shè)置的權(quán)限位. 常用于設(shè)置文件默認(rèn)的組權(quán)限. 這個(gè)配置也可以用于設(shè)置 DOS 屬性: archive (0100), system (0010), or hidden (0001).
TIP
有些windows應(yīng)用保存文件時(shí), 會(huì)創(chuàng)建一個(gè)帶.bak后綴的文件, 當(dāng)這些文件在samba共享目錄下時(shí), 所有者不一定是當(dāng)前用戶, 為了讓當(dāng)前用戶還可以編輯修改, 可以設(shè)置 force create mode = 0660 , 這樣可以保證新文件也可以被同組用戶編輯.
force directory mode
這個(gè)配置項(xiàng)用于 當(dāng)目錄權(quán)限發(fā)生變化時(shí)強(qiáng)制設(shè)置的權(quán)限位. 常用于設(shè)置組權(quán)限, 默認(rèn)為 0000.
force group
這個(gè)配置用于給所有連接上的客戶端, 只要客戶端成功通過驗(yàn)證, 都會(huì)被指定一個(gè)固定的分組. 這個(gè)分組會(huì)體現(xiàn)在新創(chuàng)建的文件和目錄上.
force user
同樣的, 這個(gè)配置會(huì)給連接上的驗(yàn)證通過的客戶端, 指定一個(gè)用戶, 體現(xiàn)在新創(chuàng)建的文件和目錄上.
關(guān)于 CIFS 和 SMB 的選擇
In this day and age, you should always use the acronym SMB. I know what you’re thinking – “but if they’re essentially the same thing, why should I always use SMB?”文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-581696.html
Two reasons:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-581696.html
- The CIFS implementation of SMB is rarely used these days. Under the covers, most modern storage systems no longer use CIFS, they use SMB 2 or SMB 3. In the Windows world, SMB 2 has been the standard as of Windows Vista (2006) and SMB 3 is part of Windows 8 and Windows Server 2012.
- CIFS has a negative connotation amongst pedants. SMB 2 and SMB 3 are massive upgrades over the CIFS dialect, and storage architects who are near and dear to file sharing protocols don’t appreciate the misnomer. It’s kind of like calling an executive assistant a secretary.
參考
- https://www.varonis.com/blog/cifs-vs-smb
- https://linuxconfig.org/how-to-configure-samba-server-share-on-ubuntu-22-04-jammy-jellyfish-linux
- https://linux.how2shout.com/how-to-install-samba-on-ubuntu-22-04-lts-jammy-linux/
- Samba配置 https://wiki.samba.org/index.php/Setting_up_Samba_as_a_Standalone_Server#Creating_a_Basic_guest_only_smb.conf_File
到了這里,關(guān)于Ubuntu 22.04 Samba 安裝和配置的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!