linux学习笔记之samba服务

好记性不如烂笔头

1、为什么要安装Samba服务?
在安装了虚拟机之后,发现里面的CentOS 7与宿主机进行文件共享不是很方便,于是就直接安装配置了Samba实现win7与CentOS 7的文件共享。Samba是一个很常见的选择:Linux运行Samba服务,Windows访问Linux上共享的文件。在不需要用户访问控制的场景下,Samba服务的安全级别设置为共享(share)就可以了。我的需求是想对Samba服务的访问者进行身份验证,所以选择用户安全级别(user)。user级别要求用户访问samba服务时提供用户名和密码,而且身份验证由 samba server 负责。下面是用smbpasswd方式做的,因我的需求很单一,所以Samba的配置文件也非常简单。这里做个笔记记录一下以备忘。
2、使用yum -y install samba samba-client samba-common安装Samba

3、查看Samba版本信息rpm -qi samba

[root@localhost samba]# rpm -qi samba
Name : samba
Epoch : 0
Version : 4.4.4
Release : 14.el7_3
Architecture: x86_64
Install Date: 2017年07月23日 星期日 11时24分02秒
Group : System Environment/Daemons
Size : 1869228
License : GPLv3+ and LGPLv3+
Signature : RSA/SHA256, 2017年05月25日 星期四 21时16分22秒, Key ID 24c6a8a7f4a80eb5
Source RPM : samba-4.4.4-14.el7_3.src.rpm
Build Date : 2017年05月25日 星期四 19时35分40秒
Build Host : c1bm.rdu2.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://www.samba.org/
Summary : Server and Client software to interoperate with Windows machines
Description :
Samba is the standard Windows interoperability suite of programs for Linux and
Unix.
    使用testparm测试下,出现以下信息正常
[root@localhost samba]# testparm
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 "[SHAREDOCS]"
Processing section "[RDDOCS]"
Loaded services file OK.
Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions
 
 4、Samba配置
先将配置文件备份下:
cp /etc/samba/smb.conf  /home/bmk/smb.conf.bak
smb.conf原有内容
1 # See smb.conf.example for a more detailed config file or
2 # read the smb.conf manpage.
3 # Run 'testparm' to verify the config is correct after
4 # you modified it.
5
6 [global]
7 workgroup = WORKGROUP
8 security = user
9
10 passdb backend = tdbsam
11
12 printing = cups
13 printcap name = cups
14 load printers = yes
15 cups options = raw
16
17 [homes]
18 comment = Home Directories
19 valid users = %S, %D%w%S
20 browseable = No
21 read only = No
22 inherit acls = Yes
23
24 [printers]
25 comment = All Printers
26 path = /var/tmp
27 printable = Yes
28 create mask = 0600
29 browseable = No
30
31 [print$]
32 comment = Printer Drivers
33 path = /var/lib/samba/drivers
34 write list = root
35 create mask = 0664
36 directory mask = 0775
 在配置文件最后添加以下内容
[SHAREDOCS]
path = /home/imix/share
readonly = yes
browseable = yes
guest ok = yes
[RDDOCS]
path = /home/www/default
public = no
writable = yes
write list = @www
validusers = @www
 5、添加samba用户(这里我直接使用操作系统的一个非root权限的用户imix)
[root@localhost samba]# smbpasswd -a imix
New SMB password:
Retype new SMB password:
Added user imix.
[root@localhost samba]# smbpasswd -e imix
Enabled user imix.
 6、重启下samba服务
[root@localhost samba]# systemctl restart smb   (service smb restart)
[root@localhost samba]#systemctl enable smb   (service smb enable)
[root@localhost samba]#systemctl status smb  (service smb status)
 7、在本地系统访问samba服务
 在开始菜单输入IP地址,然后回车,本地系统与虚拟机系统可以共享文件了
注意:有时候连接不上可能是防火墙造成
[root@base samba]# firewall-cmd --permanent --add-port=139/tcp
success
[root@base samba]# firewall-cmd --permanent --add-port=445/tcp
success
[root@base samba]# systemctl restart firewalld
7.1

 7.2

 
7.3
7.4、问题,有三个目录,imix、sharedocs正常访问,访问rddocs需要用户名和密码
 

 
因为我们在配置文件时,这个目录访问权限是www组
42 [RDDOCS]
43 path = /home/www/default
44 public = no
45 writable = yes
46 write list = @www
47 validusers = @www
 9、创建用户并分配权限
创建用户并分配权限

1、创建操作系统用户test(如果用户已经存在就不需要再创建了)

操作格式:useradd 用户名

例如:# useradd test

2、修改用户的组(需要将test都加到www组里面)

操作格式: usermod -a-G 组名 用户名

例如:# usermod -a-G www test

以上表示,将lxl用户添加到www组;

3、查看用户id信息

例如# id lxl
uid=1002(test) gid=1002(test) 组=1002(test),1001(www)

注意:adduser和useradd的区别;在使用adduser命令时,它会添加这个用户名,并创建和用户名名称相同的组名,并把这个用户名添加到自己的组里去,并在/home目录想创建和用户名同名的目录,并拷贝/etc/skel目录下的内容到/home/用户名/的目录下,并提示输入密码,并提示填写相关这个用户名的信息。在使用命令useradd时,它会添加这个用户名,并创建和用户名相同的组名,但它并不在/home目录下创建基于用户名的目录,也不提示创建新的密码。
 

猜你喜欢

转载自lintaozhou.iteye.com/blog/2392035