使用步骤:
安装与部署
准备共享目录
写配置文件
准备用户与smb用户数据库
部署与初始化 1 2 3 4 5 6 7 8 9 10 11 12 13 hostnamectl set-hostname samba-server && bash systemctl disable firewalld.service --now setenforce 0 sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config yum -y install samba mkdir /data/smb -pgroupadd ws chgrp ws /data/smbchmod 2775 /data/smb
配置文件详解 分global区域与共享区域,共享区域配置优先级高于global
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 [global] workgroup = WORKGROUP server string = File Server netbios name = FILESERVER security = user passdb backend = tdbsam hosts allow = 192.168.1.0/24 log file = /var/log/samba/log.%m max log size = 50 client min protocol = SMB2 map to guest = Bad User [public] comment = 公共共享目录 path = /data/samba browseable = Yes read only = No valid users = @samba_users create mask = 0664 directory mask = 0775 inherit acls = Yes force group = samba_users guest ok = No hosts allow = 192.168.1.0/24
配置文件修改 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 [global] workgroup = SAMBA security = user passdb backend = tdbsam printing = cups printcap name = cups load printers = yes cups options = raw [wangsheng] comment = its a test path = /data/smb valid users = xhy, @ws browseable = No read only = No write list = @ws testparm Load smb config files from /etc/samba/smb.conf Loaded services file OK. Weak crypto is allowed by GnuTLS (e.g. NTLM as a compatibility fallback) Server role: ROLE_STANDALONE
准备用户 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 useradd -g ws -s /sbin/nologin ws1 useradd -g ws -s /sbin/nologin ws2 useradd -s /sbin/nologin ws3 useradd -s /sbin/nologin xhy smbpasswd -a ws1 smbpasswd -a ws2 smbpasswd -a ws3 smbpasswd -a xhy pdbedit -L ws1:1000: ws3:1002: ws2:1001: xhy:1003: systemctl enable smb --now
在Linux上进行挂载 使用用户ws1(属于ws组,具有读写权限)
手动挂载
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 hostnamectl set-hostname smb-client1 && bash yum -y install cifs-utils mkdir /samba-sharemount -t cifs -o username=ws1,password=ws1 //10.163.2.102/wangsheng /samba-share df -ThFilesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 4.0M 0 4.0M 0% /dev tmpfs tmpfs 3.8G 0 3.8G 0% /dev/shm tmpfs tmpfs 1.6G 8.6M 1.5G 1% /run /dev/mapper/cs-root xfs 46G 3.3G 42G 8% / /dev/sda1 xfs 960M 326M 635M 34% /boot tmpfs tmpfs 769M 4.0K 769M 1% /run/user/0 //10.163.2.102/wangsheng cifs 46G 3.4G 42G 8% /samba-share touch /samba-share/test111ls /samba-share/ -ltotal 0 -rwxr-xr-x. 1 root root 0 Apr 15 21:00 test111
持久化挂载
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 echo \'//10.163.2.102/wangsheng /samba-share cifs defaults,username=ws1,password=ws1 0 0' \>> /etc/fstab umount /samba-share df -ThFilesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 4.0M 0 4.0M 0% /dev tmpfs tmpfs 3.8G 0 3.8G 0% /dev/shm tmpfs tmpfs 1.6G 8.6M 1.5G 1% /run /dev/mapper/cs-root xfs 46G 3.3G 42G 8% / /dev/sda1 xfs 960M 326M 635M 34% /boot tmpfs tmpfs 769M 4.0K 769M 1% /run/user/0 mount -a df -ThFilesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 4.0M 0 4.0M 0% /dev tmpfs tmpfs 3.8G 0 3.8G 0% /dev/shm tmpfs tmpfs 1.6G 8.6M 1.5G 1% /run /dev/mapper/cs-root xfs 46G 3.3G 42G 8% / /dev/sda1 xfs 960M 326M 635M 34% /boot tmpfs tmpfs 769M 4.0K 769M 1% /run/user/0 //10.163.2.102/wangsheng cifs 46G 3.4G 42G 8% /samba-share
测试使用无权限用户
xhy这个用户是只读不可写的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 hostnamectl set-hostname smb-client2 && bash yum -y install cifs-utils mkdir /samba-sharemount -t cifs -o username=xhy,password=xhy //10.163.2.102/wangsheng /samba-share df -ThFilesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 4.0M 0 4.0M 0% /dev tmpfs tmpfs 3.8G 0 3.8G 0% /dev/shm tmpfs tmpfs 1.6G 8.6M 1.5G 1% /run /dev/mapper/cs-root xfs 46G 3.3G 42G 8% / /dev/sda1 xfs 960M 326M 635M 34% /boot tmpfs tmpfs 769M 4.0K 769M 1% /run/user/0 //10.163.2.102/wangsheng cifs 46G 3.4G 42G 8% /samba-share ls /samba-share/test111 cp /samba-share/test111 ~touch /samba-share/test2222touch : cannot touch '/samba-share/test2222' : Permission denied
在windows上进行挂载 临时挂载
打开windows的运行
输入\10.163.2.102\wangsheng
弹出用户验证框,随后就可以访问到了,并且可以创建文件(可写)
永久挂载
计算机——映射网络驱动器