CentOS7中Samba环境搭建

Samba介绍:

Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成。SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和打印机的一种通信协议,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务。SMB协议是客户机/服务器型协议,客户机通过该协议可以访问服务器上的共享文件系统、打印机及其他资源。通过设置“NetBIOS over TCP/IP”使得Samba不但能与局域网络主机分享资源,还能与全世界的电脑分享资源。下面简单介绍下,在Centos7下部署Samba服务的操作记录(测试机192.168.1.195)

1,安装Samba

[root@promote ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
[root@promote ~]# rpm -qa | grep samba
[root@promote ~]# yum install -y samba
	已加载插件:fastestmirror
	Loading mirror speeds from cached hostfile
	 * base: mirrors.aliyun.com
	 * extras: mirrors.aliyun.com
	 * updates: mirrors.aliyun.com
	正在解决依赖关系
	--> 正在检查事务
	---> 软件包 samba.x86_64.0.4.10.16-7.el7_9 将被 安装
	……

2,关闭selinux和防火墙

[root@promote ~]# setenforce 0
[root@promote ~]# systemctl stop firewalld
[root@promote ~]# systemctl disable firewalld
	Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
	Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

3,配置Samba配置文件

[root@promote ~]# cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
[root@promote ~]# vim /etc/samba/smb.conf
[root@promote ~]# cat /etc/samba/smb.conf
	# See smb.conf.example for a more detailed config file or
	# read the smb.conf manpage.
	# Run 'testparm' to verify the config is correct after
	# you modified it.
	
	[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
	
	[durant]                            //这个是共享文件夹标识,表示登录samba打开时显示的文件夹名称。配置了多少个共享文件夹标识,登录samba时就会显示多少文件夹。                                           
	       comment = this is the info   //comment是对该共享的描述,可以是任意字符串
	       path= /home/durant           //共享的路径
	       writable = yes               //是否可写入
	       public = no                  //是否公开

4,添加durant账号(如上配置中添加的内容)

设置为不允许登入系统,且用户的家目录为 /home/durant(相当于虚拟账号)的durant(账号可以更改,只要后面保持一致即可)账号。

[root@promote ~]# useradd -d /home/durant -s /sbin/nologin durant

5,将durant添加为samba用户

[root@promote ~]# pdbedit -a -u durant
	new password:
	retype new password:
	Unix username:        durant
	NT username:          
	Account Flags:        [U          ]
	User SID:             S-1-5-21-4104757540-3263001079-3317561741-1000
	Primary Group SID:    S-1-5-21-4104757540-3263001079-3317561741-513
	Full Name:            
	Home Directory:       \\promote\durant
	HomeDir Drive:        
	Logon Script:         
	Profile Path:         \\promote\durant\profile
	Domain:               PROMOTE
	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:    六, 14 11月 2020 19:44:38 CST
	Password can change:  六, 14 11月 2020 19:44:38 CST
	Password must change: never
	Last bad password   : 0
	Bad password count  : 0
	Logon hours         : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

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用户

6,修改samba用户的家目录权限

[root@promote ~]# chown -Rf durant:durant /home/durant

7,启动Samba服务

[root@promote ~]# systemctl start smb
[root@promote ~]# systemctl enable smb
[root@promote ~]# systemctl restart smb
[root@promote ~]]# 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-11-14 20:11:47 CST; 10s ago
	     Docs: man:smbd(8)
	           man:samba(7)
	           man:smb.conf(5)
	 Main PID: 12758 (smbd)
	   Status: "smbd: ready to serve connections..."
	   CGroup: /system.slice/smb.service
	           ├─12758 /usr/sbin/smbd --foreground --no-process-group
	           ├─12760 /usr/sbin/smbd --foreground --no-process-group
	           ├─12761 /usr/sbin/smbd --foreground --no-process-group
	           └─12762 /usr/sbin/smbd --foreground --no-process-group
	
	11月 14 20:11:46 promote.cache-dns.local systemd[1]: Starting Samba SMB Daemon...
	11月 14 20:11:47 promote.cache-dns.local smbd[12758]: [2020/11/14 20:11:47.285632, ...)
	11月 14 20:11:47 promote.cache-dns.local smbd[12758]:   daemon_ready: daemon 'smbd'...s
	11月 14 20:11:47 promote.cache-dns.local systemd[1]: Started Samba SMB Daemon.
	Hint: Some lines were ellipsized, use -l to show in full.

8,测试环境

1),将samba共享目录挂载到windows上
  1. 右键“此电脑”选择“映射网络驱动器”邮件此电脑-->映射网络驱动器

  2. 输入samba的地址,点击“完成”远程主机名称

  3. 输入凭据,用户名durant,密码durant,点击“确定”,用户名和密码为第4步和第5步输入的用户名和密码。在这里插入图片描述

  4. 查看samba上的durant目录是否已经挂载到了windows的Z盘上在这里插入图片描述

2),将samba共享目录挂载到linux上(192.168.1.200)
  1. 在192.168.1.200客户机上执行以下命令
[root@promote ~]# mkdir -p /durant
[root@promote ~]# mount -t cifs //192.168.1.195/durant -o username=durant,password=durant /durant
[root@promote ~]# df -h
  1. 查看samba上的durant目录是否已经挂载到192.168.1.200Linux主机上
    在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值