文件共享服務(wù)---Samba
創(chuàng)新互聯(lián)建站網(wǎng)站建設(shè)由有經(jīng)驗(yàn)的網(wǎng)站設(shè)計(jì)師、開發(fā)人員和項(xiàng)目經(jīng)理組成的專業(yè)建站團(tuán)隊(duì),負(fù)責(zé)網(wǎng)站視覺設(shè)計(jì)、用戶體驗(yàn)優(yōu)化、交互設(shè)計(jì)和前端開發(fā)等方面的工作,以確保網(wǎng)站外觀精美、成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)易于使用并且具有良好的響應(yīng)性。
=============================================================================
★smb:Service Message Block;服務(wù)信息塊
★cifs:Common Internet File System,
★samba:作者:Andrew Tridgell;
實(shí)事上是smb功能的實(shí)現(xiàn),核心當(dāng)中所實(shí)現(xiàn)的主要協(xié)議是cifs協(xié)議
★功能:
文件系統(tǒng)共享;
NetBIOS協(xié)議(進(jìn)行Windows網(wǎng)絡(luò)上的主機(jī)名解析);
打印服務(wù);
1)程序環(huán)境
★samba安裝
# yum install samba -y
★主配置文件
/etc/samba/smb.conf
★主程序:
/usr/sbin/nmbd:
Network Naming Service,主要是完成NetBIOS名稱解析;
/usr/sbin/smbd:
SMB/CIFS Service;核心主程序,完成SMB/CIFS服務(wù)
★Unit File
/usr/lib/systemd/system/nmb.service
/usr/lib/systemd/system/smb.service
★監(jiān)聽的端口:
UDP:137/udp, 138/udp
TCP:139/tcp, 445/tcp
★客戶端程序:
mount -t cifs = mount.cifs
smbclient:交互式命令行客戶端工具;
2)samba的配置
/etc/samba/smb.conf
★主配置文件:/etc/samba/smb.conf
[root@centos7 ~]# cd /etc/samba [root@centos7 samba]# ls lmhosts smb.conf [root@centos7 samba]# cp smb.conf{,.bak} # 首先備份 [root@centos7 samba]# ls lmhosts smb.conf smb.conf.bak [root@centos7 samba]# grep -i -E "^#[[:space:]]*(=|-)+" smb.conf # 過濾出配置段 #--------------- #-------------- # 全局配置段 #======================= Global Settings ===================================== # ----------------------- Network-Related Options ------------------------- # --------------------------- Logging Options ----------------------------- # ----------------------- Standalone Server Options ------------------------ # ----------------------- Domain Members Options ------------------------ # ----------------------- Domain Controller Options ------------------------ # ----------------------- Browser Control Options ---------------------------- #----------------------------- Name Resolution ------------------------------- # --------------------------- Printing Options ----------------------------- # --------------------------- File System Options --------------------------- #============================ Share Definitions ============================== # 用戶自定義的共享配置段★兩類配置段:
◎全局配置
[global]
workgroup = MYGROUP 工作組模型 用來定義工作組
server string = Samba Server Version %v 定義提示信息
interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24 指明要監(jiān)聽的地址或網(wǎng)絡(luò)接口;
hosts allow = 127. 192.168.12. 192.168.13. 訪問控制,相當(dāng)于白名單
log file = /var/log/samba/log.%m 每個(gè)客戶端將使用自己專用的日志文件;
max log size = 50 指明日志文件大小,默認(rèn)為KB
security = user 定義安全級(jí)別,user提供賬號(hào)和密碼
share (depricated) 匿名共享
server (depricated) 實(shí)現(xiàn)集中式身份認(rèn)證
domain
passdb backend = tdbsam 賬號(hào)密碼的存儲(chǔ)格式
load printers = yes samba 服務(wù)啟動(dòng)時(shí)是否裝載打印機(jī)驅(qū)動(dòng)
cups options = raw 通用的打印機(jī)的服務(wù)方式
◎共享文件系統(tǒng):
[shared_ID]
有三類:
[homes]:每個(gè)samba用戶是否能夠通過samba服務(wù)訪問其家目錄;
[printers]:打印服務(wù);
[shared_FS]:用戶自定義的共享目錄;
常用指令:
comment:注釋信息;
path:本地文件系統(tǒng)路徑;
browseable:是否可瀏覽,是否為用戶可見;
guest ok:是否允許來賓賬號(hào)(匿名用戶)訪問;
public:是否公開給所有來賓;
writable:是否可寫;
writable=YES和read only = no是一樣的
write list:擁有寫權(quán)限的用戶或組列表;
用戶名
@組名 = +組名
2)samba用戶管理
★命令:
smbpasswd, pdbedit
1)smbpasswd
語法:
smbpasswd [OPTIONS] USERNAME(系統(tǒng)用戶)
選項(xiàng):
-a:添加;
-x:刪除;
-d:禁用;
-e:?jiǎn)⒂?/p>
2)pdbedit:
-L:列出samba服務(wù)中的所有用戶;
-a:添加用戶為samba用戶;
-u USERNAME:
-x:刪除
-t:從標(biāo)準(zhǔn)輸出接收密碼;
★訪問服務(wù):
☉smbclient交互式客戶端程序:
查看目標(biāo)服務(wù)上的共享
smbclient -L SMB_SERVER [-U USERNAME]
訪問共享服務(wù)
smbclient //SMB_SERVER[/SHARE_NAME] [-U USERNAME]
☉mount.cifs
mount -t cifs //SMB_SERVER/SHARED_ID /MOUNT_POINT -o username=USER,password=PASS(指明用戶身份和密碼)
注意:
掛載操作中的用戶,與-o選項(xiàng)中指定的用戶直接產(chǎn)生映射關(guān)系;訪問掛載,是以-o選項(xiàng)指定的用戶身份運(yùn)行,與本地用戶以ID產(chǎn)生映射;
★自定義共享的方式:
[shared_ID]
comment =
path =
guest ok =
read only =
public =
browseable =
write list =
☉注意:
定義所有用戶在服務(wù)級(jí)的寫權(quán)限write = yes (read only = no)不建議與write list同時(shí)使用;
命令演示:
1.添加用戶
[root@centos7 ~]# pdbedit -a -u tao # 添加用戶 new password: retype new password: Unix username: tao NT username: Account Flags: [U ] User SID: S-1-5-21-1194301372-4224252613-970535052-1000 Primary Group SID: S-1-5-21-1194301372-4224252613-970535052-513 Full Name: Home Directory: \\centos7\tao HomeDir Drive: Logon Script: Profile Path: \\centos7\tao\profile Domain: CENTOS7 Account desc: Workstations: Munged dial: Logon time: 0 Logoff time: Wed, 06 Feb 2036 23:06:39 CST Kickoff time: Wed, 06 Feb 2036 23:06:39 CST Password last set: Tue, 18 Oct 2016 23:24:50 CST Password can change: Tue, 18 Oct 2016 23:24:50 CST Password must change: never Last bad password : 0 Bad password count : 0 Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF [root@centos7 ~]# pdbedit -L # 列出samba用戶 tao:1000: [root@centos7 ~]# pdbedit -a -u xiu # 再添加一個(gè)用戶xiu [root@centos7 ~]# pdbedit -L tao:1000: xiu:1001:
啟動(dòng)samba服務(wù),并查看端口號(hào)
[root@centos7 ~]# systemctl start nmb.service smb.service [root@centos7 ~]# ss -unl # 查看udp端口 137,138 State Recv-Q Send-Q Local Address:Port Peer Address:Port UNCONN 0 0 *:68 *:* UNCONN 0 0 192.168.1.255:137 *:* UNCONN 0 0 192.168.1.15:137 *:* UNCONN 0 0 *:137 *:* UNCONN 0 0 192.168.1.255:138 *:* UNCONN 0 0 192.168.1.15:138 *:* UNCONN 0 0 *:138 *:* UNCONN 0 0 127.0.0.1:323 *:* UNCONN 0 0 *:34320 *:* UNCONN 0 0 :::10025 :::* UNCONN 0 0 ::1:323 :::* [root@centos7 ~]# ss -tnl # 查看tcp協(xié)議端口 139,445 State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 127.0.0.1:6012 *:* LISTEN 0 50 *:445 *:* LISTEN 0 50 *:3306 *:* LISTEN 0 50 *:139 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 127.0.0.1:6010 *:* LISTEN 0 128 127.0.0.1:6011 *:* LISTEN 0 128 ::1:6012 :::* LISTEN 0 50 :::445 :::* LISTEN 0 50 :::139 :::* LISTEN 0 128 :::22 :::* LISTEN 0 128 ::1:631 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 ::1:6010 :::* LISTEN 0 128 ::1:6011 :::*
2.smbclient命令查看目標(biāo)主機(jī)上的共享
這里以centos 6 主機(jī)作為客戶端,訪問作為samba服務(wù)器的centos 7
# 匿名訪問,不輸入密碼,如下: [root@CentOS6 ~]# smbclient -L 192.168.1.15 Enter root's password: Anonymous login successful Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3] Sharename Type Comment --------- ---- ------- IPC$ IPC IPC Service (Samba Server Version 4.2.3) Anonymous login successful Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3] Server Comment --------- ------- CENTOS7 Samba Server Version 4.2.3 Workgroup Master --------- ------- MYGROUP CENTOS7 WORKGROUP PC-20160624QLWL # 已創(chuàng)建的系統(tǒng)用戶賬號(hào)來訪問,如下: [root@CentOS6 ~]# smbclient -L 192.168.1.15 -U tao Enter tao's password: Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3] Sharename Type Comment --------- ---- ------- IPC$ IPC IPC Service (Samba Server Version 4.2.3) tao Disk Home Directories Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3] Server Comment --------- ------- CENTOS7 Samba Server Version 4.2.3 Workgroup Master --------- ------- MYGROUP CENTOS7 WORKGROUP PC-20160624QLWL
3.smbclient命令訪問目標(biāo)主機(jī)上的共享服務(wù)
[root@CentOS6 ~]# smbclient //192.168.1.15/ -U tao Enter tao's password: [root@CentOS6 ~]# smbclient //192.168.1.15/tao -U tao # 要添加允許訪問的共享的目錄文件 Enter tao's password: Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3] smb: \> help # 獲取幫助 ? allinfo altname archive blocksize cancel case_sensitive cd chmod chown close del dir du echo exit get getfacl geteas hardlink help history iosize lcd link lock lowercase ls l mask md mget mkdir more mput newer open posix posix_encrypt posix_open posix_mkdir posix_rmdir posix_unlink print prompt put pwd q queue quit readlink rd recurse reget rename reput rm rmdir showacls setea setmode stat symlink tar tarmode timeout translate unlock volume vuid wdel logon listconnect showconnect .. ! smb: \> pwd # 顯示的是samba服務(wù)器上系統(tǒng)用戶tao的共享目錄,配置中家目錄是允許共享的 Current directory is \\192.168.1.15\tao\ smb: \> ls . D 0 Tue Oct 18 13:09:36 2016 .. D 0 Tue Oct 18 11:38:44 2016 .mozilla DH 0 Mon Jul 25 23:57:35 2016 .bash_logout H 18 Fri Nov 20 13:02:30 2015 .bash_profile H 193 Fri Nov 20 13:02:30 2015 .bashrc H 231 Fri Nov 20 13:02:30 2015 .zshrc H 658 Fri Nov 20 21:11:02 2015 .Xauthority H 53 Sun Sep 11 11:11:49 2016 .cache DH 0 Sun Sep 11 11:11:49 2016 .config DH 0 Tue Oct 18 12:38:09 2016 .bash_history H 361 Tue Oct 18 12:43:06 2016 .MySQL_history H 268 Mon Oct 17 16:18:28 2016 pub D 0 Tue Oct 18 09:16:21 2016 upload D 0 Tue Oct 18 09:20:53 2016 xiu D 0 Tue Oct 18 09:36:02 2016 .local DH 0 Tue Oct 18 12:38:09 2016 f1 13 Tue Oct 18 13:09:36 2016 40940 blocks of size 1048576. 40072 blocks available smb: \> put /etc/fstab # 上傳Cen 6 中的文件發(fā)現(xiàn)不能上傳,這里最要使用當(dāng)前路徑 NT_STATUS_OBJECT_PATH_NOT_FOUND opening remote file \/etc/fstab smb: \> lcd /etc # 切換到要上傳文件的當(dāng)前目錄中 smb: \> put fstab # 上傳文件,發(fā)現(xiàn)可以上傳,這是因?yàn)橄到y(tǒng)文件中定義的writable=YES,有寫權(quán)限,并且tao用戶對(duì)自己的家目錄也有寫權(quán)限 putting file fstab as \fstab (52.3 kb/s) (average 52.3 kb/s) smb: \> ls . D 0 Wed Oct 19 00:11:59 2016 .. D 0 Tue Oct 18 11:38:44 2016 .mozilla DH 0 Mon Jul 25 23:57:35 2016 .bash_logout H 18 Fri Nov 20 13:02:30 2015 .bash_profile H 193 Fri Nov 20 13:02:30 2015 .bashrc H 231 Fri Nov 20 13:02:30 2015 .zshrc H 658 Fri Nov 20 21:11:02 2015 .Xauthority H 53 Sun Sep 11 11:11:49 2016 .cache DH 0 Sun Sep 11 11:11:49 2016 .config DH 0 Tue Oct 18 12:38:09 2016 .bash_history H 361 Tue Oct 18 12:43:06 2016 .mysql_history H 268 Mon Oct 17 16:18:28 2016 pub D 0 Tue Oct 18 09:16:21 2016 upload D 0 Tue Oct 18 09:20:53 2016 xiu D 0 Tue Oct 18 09:36:02 2016 .local DH 0 Tue Oct 18 12:38:09 2016 f1 13 Tue Oct 18 13:09:36 2016 fstab #已上傳的文件 A 1017 Wed Oct 19 00:11:59 2016 40940 blocks of size 1048576. 40072 blocks available smb: \> ^C
4.自定義共享服務(wù)
[root@centos7 ~]# mkdir -pv /samba/tools # 創(chuàng)建共享的目錄 mkdir: created directory ‘/samba’ mkdir: created directory ‘/samba/tools’ [root@centos7 ~]# vim /etc/samba/smb.conf # 編輯主配置文件 [apps] # 自定義一個(gè)共享名 comment = tools # 注釋為tools工具 path = /samba/tools # 本地文件系統(tǒng)路徑 browseable = yes # 允許非屬主,數(shù)組瀏覽 guest ok = yes # 允許來賓訪問,即匿名用戶 writable = yes # 允許寫操作(如:上傳和刪除等) # 配置好之后保存退出,并測(cè)試語法 [root@centos7 samba]# testparm # 語法測(cè)試 Load smb config files from /etc/samba/smb.conf rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384) Processing section "[homes]" Processing section "[printers]" Processing section "[apps]" Loaded services file OK. Server role: ROLE_STANDALONE Press enter to see a dump of your service definitions # 敲回車,打印出服務(wù)所有的生效配置 # Global parameters [global] workgroup = MYGROUP server string = Samba Server Version %v security = USER log file = /var/log/samba/log.%m max log size = 50 idmap config * : backend = tdb cups options = raw [homes] comment = Home Directories read only = No browseable = No [printers] comment = All Printers path = /var/spool/samba printable = Yes print ok = Yes browseable = No [apps] comment = tools path = /samba/tools read only = No # 非只讀,代表可寫 guest ok = Yes [root@centos7 samba]# systemctl restart smb 重啟服務(wù)
查看共享服務(wù),并訪問
# 查看系統(tǒng)用戶下的共享服務(wù) [root@CentOS6 ~]# smbclient -L 192.168.1.15 -U tao Enter tao's password: Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3] Sharename Type Comment --------- ---- ------- apps Disk tools
分享題目:文件共享服務(wù)---Samba
網(wǎng)站地址:http://weahome.cn/article/gdceed.html