一、环境准备

1. 卸载原有samba

[root@localhost ~]# rpm -qa|grep samba
[root@localhost ~]# rpm -e —nodeps samba-x.x.x-10.el7_7.x86_64

2. 关闭selinux和防火墙

[root@localhost ~]# sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/sysconfig/selinux
[root@localhost ~]# sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config
[root@localhost ~]# sestatus

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld

二、安装samba

[root@localhost ~]# yum install -y samba
[root@localhost ~]# cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
[root@localhost ~]# vim /etc/samba/smb.conf

  1. [global]
  2. workgroup = SAMBA
  3. security = user
  4. passdb backend = tdbsam
  5. printing = cups
  6. printcap name = cups
  7. load printers = yes
  8. cups options = raw
  9. [homes]
  10. comment = Home Directories
  11. valid users = %S, %D%w%S
  12. browseable = No
  13. read only = No
  14. inherit acls = Yes
  15. [printers]
  16. comment = All Printers
  17. path = /var/tmp
  18. printable = Yes
  19. create mask = 0600
  20. browseable = No
  21. [print$]
  22. comment = Printer Drivers
  23. path = /var/lib/samba/drivers
  24. write list = @printadmin root
  25. force group = @printadmin
  26. create mask = 0664
  27. directory mask = 0775
  28. [tomcat]
  29. comment = tomcat log
  30. path= /soft/apache-tomcat7-8089/logs
  31. writable = yes
  32. public = no

[root@localhost ~]# useradd -d /soft/apache-tomcat7-8089/logs -s /sbin/nologin tomcat
(创建tomcat用户,指定其目录为/soft/apache-tomcat7-8089/logs,且不可登陆操作系统)
[root@localhost ~]# passwd tomcat
(给tomcat用户创建密码)

备注:
path= /soft/apache-tomcat7-8089/logs :共享目录的路径
writable = yes :用户可写权限,yes为可写
public = no 为匿名用户访问权限,no为不可访问

三、将创建的系统用户映射为samba用户

[root@localhost ~]# pdbedit -a -u tomcat
new password:
retype new password:

[root@localhost ~]# pdbedit -L (查看samba的所有用户)

四、启动samba

[root@localhost ~]# systemctl start smb
[root@localhost ~]# systemctl enable smb
[root@localhost ~]# systemctl status smb

五、测试

Windows电脑上输入:\10.6.5.112

Linux挂载samba

六、补充

pdbedit 和smbpasswd 命令都可用户将系统用户映射为samba用户

1. pdbedit 命令

pdbedit -L :查看samba用户
pdbedit -a -u user:添加samba用户
pdbedit -r -u user:修改samba用户信息
pdbedit -x -u user:删除samba用户

2. smbpasswd 命令

smbpasswd -a user:添加一个samba用户
smbpasswd -d user:禁用一个samba用户
smbpasswd -e user:恢复一个samba用户
smbpasswd -x user:删除一个samba用户