Linux下的samba服务配置详解
Linux下的samba服務(wù)配置詳解
- 一、Samba介紹
- 二、Samba工具及特性
- 三、搭建環(huán)境介紹
- 四、Samba配置步驟
- 1.服務(wù)端操作
- 2.在客戶端操作
- 五、測試用戶的權(quán)限情況
一、Samba介紹
1.SMB(Server Messages Block,信息服務(wù)塊)是一種在局域網(wǎng)上共享文件和打印機的一種通信協(xié)議,它為局域網(wǎng)內(nèi)的不同計算機之間提供文件及打印機等資源的共享服務(wù)。
2.Samba是在Linux和UNIX系統(tǒng)上實現(xiàn)SMB協(xié)議的一個免費軟件,由服務(wù)器及客戶端程序構(gòu)成。
3.其他相關(guān)概念:
CIFS:common internet file system,微軟基于SMB發(fā)布。
NFS:網(wǎng)絡(luò)文件系統(tǒng),英文Network File System(NFS),是由SUN公司研制的UNIX表示層協(xié)議(presentation layer protocol),能使使用者訪問網(wǎng)絡(luò)上別處的文件就像在使用自己的計算機一樣。
二、Samba工具及特性
1.相關(guān)包
①amba 提供smb服務(wù)
②samba-client 客戶端軟件
③samba-common 通用軟件
④cifs-utils smb客戶端工具
⑤samba-winbind 和AD相關(guān)
2.相關(guān)服務(wù)進程
smbd 提供smb(cifs)服務(wù) TCP:139,445
nmbd NetBIOS名稱解析 UDP:137,138
3.相關(guān)工具及命令
主配置文件:/etc/samba/smb.conf
語法檢查: testparm [-v] [/etc/samba/smb.conf]
客戶端工具:smbclient,pdnedit -L(列出Samba用戶列表,讀取passdb.tdb數(shù)據(jù)庫文件)
三、搭建環(huán)境介紹
1.使用操作系統(tǒng)為RHEL8.0
2.Samba用戶為三個(kitty,buer,alice),都可以瀏覽共享目錄/share/,kitty和buer可以寫入文件共享目錄。
3.服務(wù)端hostname為control,客戶端hostname為node1
四、Samba配置步驟
1.服務(wù)端操作
①在server端安裝軟件包
[root@control ~]# yum -y install samba samba-client Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Last metadata expiration check: 0:00:36 ago on Sun 02 May 2021 08:10:41 PM CST. Dependencies resolved. ================================================================================================================================================Package Arch Version Repository Size ================================================================================================================================================ Installing:samba x86_64 4.9.1-8.el8 BaseOS 708 ksamba-client x86_64 4.9.1-8.el8 BaseOS 636 k Installing dependencies:samba-common-tools x86_64 4.9.1-8.el8 BaseOS 461 ksamba-libs x86_64 4.9.1-8.el8 BaseOS 177 kTransaction Summary ================================================================================================================================================ Install 4 PackagesTotal size: 1.9 M Installed size: 5.6 M Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transactionPreparing : 1/1 Installing : samba-libs-4.9.1-8.el8.x86_64 1/4 Running scriptlet: samba-libs-4.9.1-8.el8.x86_64 1/4 Installing : samba-common-tools-4.9.1-8.el8.x86_64 2/4 Installing : samba-4.9.1-8.el8.x86_64 3/4 Running scriptlet: samba-4.9.1-8.el8.x86_64 3/4 Installing : samba-client-4.9.1-8.el8.x86_64 4/4 Running scriptlet: samba-client-4.9.1-8.el8.x86_64 4/4 Verifying : samba-4.9.1-8.el8.x86_64 1/4 Verifying : samba-client-4.9.1-8.el8.x86_64 2/4 Verifying : samba-common-tools-4.9.1-8.el8.x86_64 3/4 Verifying : samba-libs-4.9.1-8.el8.x86_64 4/4 Installed products updated.Installed:samba-4.9.1-8.el8.x86_64 samba-client-4.9.1-8.el8.x86_64 samba-common-tools-4.9.1-8.el8.x86_64 samba-libs-4.9.1-8.el8.x86_64 Complete!②創(chuàng)建samba共享目錄/share,設(shè)置權(quán)限,并拷貝文件到共享目錄
[root@control ~]# mkdir /share [root@control ~]# ll /share total 0 [root@control ~]# ll -ld /share drwxr-xr-x. 2 root root 6 May 2 20:24 /share [root@control ~]# chmod 777 /share [root@control ~]# ll -ld /share drwxrwxrwx. 2 root root 6 May 2 20:24 /share[root@control ~]# cp /etc/passwd /share [root@control ~]# cp /etc/group /share [root@control ~]# ls /share group passwd③創(chuàng)建samba用戶
[root@control ~]# groupadd it [root@control ~]# useradd -g it kitty [root@control ~]# useradd alice [root@control ~]# useradd buer [root@control ~]# smbpasswd -a kitty New SMB password: Retype new SMB password: Added user kitty. [root@control ~]# smbpasswd -a alice New SMB password: Retype new SMB password: Added user alice. [root@control ~]# smbpasswd -a buer New SMB password: Retype new SMB password: Added user buer. #查看samba用戶列表 [root@control ~]# pdbedit -L kitty:2034: buer:2036: alice:2035:④編輯samba主配置文件
進入配置目錄/etc/samba/smb.conf
測試配置文件語法
[root@control ~]# testparm /etc/samba/smb.conf 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 "[print$]" Processing section "[share]" Loaded services file OK. Server role: ROLE_STANDALONEPress enter to see a dump of your service definitions# Global parameters [global]printcap name = cupssecurity = USERworkgroup = SAMBAidmap config * : backend = tdbcups options = raw[homes]browseable = Nocomment = Home Directoriesinherit acls = Yesread only = Novalid users = %S %D%w%S[printers]browseable = Nocomment = All Printerscreate mask = 0600path = /var/tmpprintable = Yes[print$]comment = Printer Driverscreate mask = 0664directory mask = 0775force group = @printadminpath = /var/lib/samba/driverswrite list = @printadmin root[share]hosts allow = 192.168.200.0/24path = /sharewrite list = @it buer⑤啟動samba服務(wù)
[root@control ~]# systemctl start smb [root@control ~]# systemctl start nmb [root@control ~]# systemctl enable nmb Created symlink /etc/systemd/system/multi-user.target.wants/nmb.service → /usr/lib/systemd/system/nmb.service. [root@control ~]# systemctl enable smb Created symlink /etc/systemd/system/multi-user.target.wants/smb.service → /usr/lib/systemd/system/smb.service.⑥防火墻放行
[root@control ~]# firewall-cmd --permanent --add-service=samba success [root@control ~]# firewall-cmd --reload success⑦配置selinux安全標(biāo)簽
[root@control ~]# semanage fcontext -a -t samba_share_t '/share(/.*)?' [root@control ~]# restorecon restorecon restorecon_xattr [root@control ~]# restorecon -vvFR /share Relabeled /share from unconfined_u:object_r:default_t:s0 to system_u:object_r:samba_share_t:s0 Relabeled /share/passwd from unconfined_u:object_r:default_t:s0 to system_u:object_r:samba_share_t:s0 Relabeled /share/group from unconfined_u:object_r:default_t:s0 to system_u:object_r:samba_share_t:s02.在客戶端操作
①客戶端安裝相關(guān)軟件包
[root@node1 yum.repos.d]# yum -y install samba-client cifs-utils Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Repository AppStream is listed more than once in the configuration Repository BaseOS is listed more than once in the configuration AppStream 3.1 MB/s | 3.2 kB 00:00 BaseOS 2.7 MB/s | 2.7 kB 00:00 ansiable 0.0 B/s | 0 B 00:00 Failed to synchronize cache for repo 'ansiable', ignoring this repo. Dependencies resolved. ================================================================================================================================================Package Arch Version Repository Size ================================================================================================================================================ Installing:cifs-utils x86_64 6.8-2.el8 BaseOS 93 ksamba-client x86_64 4.9.1-8.el8 BaseOS 636 kTransaction Summary ================================================================================================================================================ Install 2 PackagesTotal size: 729 k Installed size: 2.3 M Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transactionPreparing : 1/1 Installing : samba-client-4.9.1-8.el8.x86_64 1/2 Running scriptlet: samba-client-4.9.1-8.el8.x86_64 1/2 Installing : cifs-utils-6.8-2.el8.x86_64 2/2 Running scriptlet: cifs-utils-6.8-2.el8.x86_64 2/2 Verifying : cifs-utils-6.8-2.el8.x86_64 1/2 Verifying : samba-client-4.9.1-8.el8.x86_64 2/2 Installed products updated.Installed:cifs-utils-6.8-2.el8.x86_64 samba-client-4.9.1-8.el8.x86_64 Complete!②使用smbclient工具測試kitty和alice用戶是否可以查看共享文件夾
[root@node1 yum.repos.d]# smbclient -L //192.168.200.150 -U kitty%redhatSharename Type Comment--------- ---- -------print$ Disk Printer Driversshare Disk IPC$ IPC IPC Service (Samba 4.9.1)kitty Disk Home Directories Reconnecting with SMB1 for workgroup listing.Server Comment--------- -------Workgroup Master--------- -------SAMBA CONTROL [root@node1 yum.repos.d]# smbclient -L //192.168.200.150 -U alice%redhatSharename Type Comment--------- ---- -------print$ Disk Printer Driversshare Disk IPC$ IPC IPC Service (Samba 4.9.1)alice Disk Home Directories Reconnecting with SMB1 for workgroup listing.Server Comment--------- -------Workgroup Master--------- -------SAMBA CONTROL③創(chuàng)建samba認證用戶文件smbur,使用alice作為認證用戶
[root@node1 yum.repos.d]# echo "username=alice" >> /etc/samba/smbur.txt [root@node1 yum.repos.d]# echo "password=redhat" >> /etc/samba/smbur.txt④編輯/etc/fstab文件,使掛載共享目錄永久生效
[root@node1 yum.repos.d]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Fri Mar 19 22:21:55 2021 # # Accessible filesystems, by reference, are maintained under '/dev/disk/'. # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info. # # After editing this file, run 'systemctl daemon-reload' to update systemd # units generated from this file. # UUID=b7190d80-906f-4b9d-9ab4-5a503ecaea2c / xfs defaults 0 0 UUID=525a30a7-d484-4ed5-9f38-f827f54e29ff /boot xfs defaults 0 0 UUID=e6cf8733-5eec-4942-9429-c3e9087b6ff0 swap swap defaults 0 0//192.168.200.150/share /media cifs defaults,credentials=/etc/samba/smbur.txt,multiuser,sec=ntlmssp 0 0 [root@node1 yum.repos.d]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 970M 0 970M 0% /dev tmpfs 984M 0 984M 0% /dev/shm tmpfs 984M 9.1M 974M 1% /run tmpfs 984M 0 984M 0% /sys/fs/cgroup /dev/nvme0n1p3 18G 4.0G 14G 23% / /dev/nvme0n1p1 495M 140M 356M 29% /boot tmpfs 197M 4.0K 197M 1% /run/user/0 /dev/sr0 6.7G 6.7G 0 100% /mnt/cdrom //192.168.200.150/share 13G 8.5G 4.1G 68% /media五、測試用戶的權(quán)限情況
1.檢查在/media目錄下以alice用戶掛載權(quán)限
[root@node1 yum.repos.d]# cd /media/ [root@node1 media]# touch file1 touch: cannot touch 'file1': Permission denied [root@node1 media]# ls group passwd2.切換本地admin用戶,以kitty和buer這兩個samba用戶訪問測試權(quán)限
[root@node1 yum.repos.d]# cd /media/ [root@node1 media]# touch file1 touch: cannot touch 'file1': Permission denied [root@node1 media]# ls group passwd [root@node1 media]# useradd admin [root@node1 media]# su - admin [admin@node1 ~]$ cd /media [admin@node1 media]$ cifscreds add -u kitty control Password: [admin@node1 media]$ ls group passwd [admin@node1 media]$ touch file1 [admin@node1 media]$ ls file1 group passwd [admin@node1 media]$ cifscreds update -u buer control Password: [admin@node1 media]$ ls file1 group passwd [admin@node1 media]$ touch file2 [admin@node1 media]$ ls file1 file2 group passwd總結(jié)
以上是生活随笔為你收集整理的Linux下的samba服务配置详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux下的rsync远程增量备份详解
- 下一篇: Linux下脚本实战之系统监控