Samba是用于Linux和Unix的标准Windows互操作性程序套件。
Samba是根据GNU通用公共许可证许可的自由软件,Samba项目是Software Freedom Conservancy的成员。
自1992年以来,Samba便为使用SMB / CIFS协议的所有客户端(包括所有版本的DOS和Windows,OS / 2,Linux等)提供安全,稳定和快速的文件和打印服务。
Samba是将Linux / Unix服务器和桌面无缝集成到Active Directory环境中的重要组件。它既可以充当域控制器,也可以充当常规域成员。
一、安装Samba
[root@jiaxu ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@jiaxu ~]# rpm -qa | grep samba
[root@jiaxu ~]# yum install -y samba
二、关闭selinux和防火墙
[root@jiaxu ~]# setenforce 0
[root@jiaxu ~]# systemctl stop firewalld
[root@jiaxu ~]# systemctl disable firewalld
三、配置Samba配置文件
[root@jiaxu ~]# cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
[root@jiaxu ~]# vim /etc/samba/smb.conf
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
[bhg] # 这个是共享文件夹标识,表示登录samba打开时显示的文件夹名称。
comment = hello bhg # comment是对该共享的描述,可以是任意字符串
path= /home/bhg # 共享的路径
writable = yes # 是否可写入
public = no # 是否公开
四、添加bhg账号(如上配置中添加的内容)
设置为不予许登入系统,且用户的家目录为 /home/bhg(相当于虚拟账号)的bhg账号。
[root@jiaxu ~]# useradd -d /home/bhg -s /sbin/nologin bhg
五、pdbedit 命令说明
pdbedit 命令用于管理Samba服务的帐户信息数据库,格式为:"pdbedit [选项] 帐户"
第一次把用户信息写入到数据库时需要使用-a参数,以后修改用户密码、删除用户等等操作就不再需要了。
pdbedit -L :查看samba用户
pdbedit -a -u user:添加samba用户
pdbedit -r -u user:修改samba用户信息
pdbedit -x -u user:删除samba用户
samba服务数据库的密码也可以用 smbpasswd 命令 操作
smbpasswd -a user:添加一个samba用户
smbpasswd -d user:禁用一个samba用户
smbpasswd -e user:恢复一个samba用户
smbpasswd -x user:删除一个samba用户
六、将bhg添加为samba用户
[root@jiaxu ~]# pdbedit -a -u bhg
new password:
retype new password:
Unix username: bhg
NT username:
Account Flags: [U ]
User SID: S-1-5-21-2708893917-4021546239-1252418083-1000
Primary Group SID: S-1-5-21-2708893917-4021546239-1252418083-513
Full Name:
Home Directory: jiaxubhg
HomeDir Drive:
Logon Script:
Profile Path: jiaxubhgprofile
Domain: JIAXU
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: 三, 06 2月 2036 23:06:39 CST
Kickoff time: 三, 06 2月 2036 23:06:39 CST
Password last set: 五, 03 4月 2020 12:29:16 CST
Password can change: 五, 03 4月 2020 12:29:16 CST
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
接着修改samba用户的家目录权限
[root@jiaxu home]# chown -Rf bhg:bhg /home/bhg
七、启动Samba服务
[root@jiaxu home]# systemctl start smb
[root@jiaxu home]# systemctl enable smb
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
[root@jiaxu home]# systemctl restart smb
[root@jiaxu home]# systemctl status smb
● smb.service - Samba SMB Daemon
Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; vendor preset: disabled)
Active: active (running) since 五 2020-04-03 12:30:49 CST; 6s ago
Docs: man:smbd(8)
man:samba(7)
man:smb.conf(5)
Main PID: 3147 (smbd)
Status: "smbd: ready to serve connections..."
CGroup: /system.slice/smb.service
├─3147 /usr/sbin/smbd --foreground --no-process-group
├─3149 /usr/sbin/smbd --foreground --no-process-group
├─3150 /usr/sbin/smbd --foreground --no-process-group
└─3151 /usr/sbin/smbd --foreground --no-process-group
4月 03 12:30:49 jiaxu systemd[1]: Stopped Samba SMB Daemon.
4月 03 12:30:49 jiaxu systemd[1]: Starting Samba SMB Daemon...
4月 03 12:30:49 jiaxu smbd[3147]: [2020/04/03 12:30:49.620282, 0] ../lib/util/become_daemon.c:138(daemon_ready)
4月 03 12:30:49 jiaxu systemd[1]: Started Samba SMB Daemon.
4月 03 12:30:49 jiaxu smbd[3147]: daemon_ready: STATUS=daemon 'smbd' finished starting up and ready to serve connections
Hint: Some lines were ellipsized, use -l to show in full.
八、测试
共享路径/home/bhg里添加点内容
[root@jiaxu /]# cd /home/bhg
[root@jiaxu bhg]# touch test{1..10}.txt
[root@jiaxu bhg]# mkdir test
[root@jiaxu bhg]# ls
test test10.txt test1.txt test2.txt test3.txt test4.txt test5.txt test6.txt test7.txt test8.txt test9.txt
[root@jiaxu bhg]#
1.将samba共享目录挂载到windows上
1)”Win+E键"打开,右键“此电脑”选择“映射网络驱动器”
测试正常。
PS:网络文件夹目前是以其他用户名和密码进行映射的——映射盘更换登录用户名问题
解决方法:
首先在我dos窗口输入命令:net use 即可看到当前已建立的连接:
然后我们输入命令:net use * /delete 来结束所有的当前所有的连接。然后再输入命令: Y 来结束所有连接;