Samba用户验证(一)
安装相关软件:yum -y install samba samba-client
启动Samba服务:
service smb start
设置开机自动启动Samba服务:
chkconfig --level 35 smb on
插入防火墙规则:(打开TCP 139,445端口)
iptables -I INPUT -p tcp -m multiport --dport 139,445 -j ACCEPT
插入防火墙规则:(打开UDP 137,138端口)
iptables -I INPUT -p udp -m multiport --dport 137,138 -j ACCEPT
笺注: 加上参数 -m multiport 就可以一次性打开多个端口
保存防火墙规则:
[root@localhost ~]# iptables-save > /etc/sysconfig/iptables
查看防火墙的filter表:
[root@localhost ~]# iptables -nL --line
[attach]7745[/attach]
查看防火墙的配置文件:
[root@localhost ~]# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Thu Jul 5 04:45:37 2018
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [48:6200]
[color=Purple]-A INPUT -p udp -m multiport --dports 137,138 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 139,445 -j ACCEPT [/color]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Thu Jul 5 04:45:37 2018
必须要关闭SELinux:(否则客户端将无法访问共享文件夹的!!)
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
人员:
财务部:c1(组长),c2(组员)
市场部:s1(组长),s2(组员)
主管:zhuohua
共享文件夹:
财务部,市场部,public
要求:
组员对自己部门的共享文件夹只有读取权限,对public文件夹只有读取权限
组长对自己部门的共享文件夹有完全权限,对public文件夹只有读取权限
所以人员都有自己的家目录,并且对家目录有完全权限
主管对所有共享文件夹都具有完全权限(但看不到其他人员的家目录的)
实验中Samba服务器IP为 192.168.168.130
Samba用户必须先是系统用户,还必须有Samba密码(与系统用户的密码无关的)
管理Samba用户的两个命令:
[color=Blue]smbpasswd --help
pdbedit --help[/color]
useradd -s /sbin/nologin zhuohua
smbpasswd -a zhuohua
[attach]7746[/attach]
groupadd caiwu
useradd -g caiwu -s /sbin/nologin c1
useradd -g caiwu -s /sbin/nologin c2
smbpasswd -a c1
smbpasswd -a c2
[attach]7747[/attach]
groupadd shichang
adduser -g shichang -s /sbin/nologin s1
adduser -g shichang -s /sbin/nologin s2
smbpasswd -a s1
smbpasswd -a s2
[attach]7748[/attach]
查询所有的Samba用户:
[attach]7749[/attach]
新建共享文件夹
mkdir -p /share/shichang
mkdir -p /share/caiwu
mkdir -p /share/public
权限必须为777
chmod -R 777 /share/shichang/
chmod -R 777 /share/caiwu/
chmod -R 777 /share/public/
修改samba的配置文件:
“MYGROUP”改成“WORKGROUP”:(WORKGROUP是Windows默认的工作组名字)
sed -i 's/workgroup = MYGROUP/workgroup = WORKGROUP/g' /etc/samba/smb.conf
“security”指定samba的安全等级。user:用户验证(默认就是user了)
security = user
不加载打印机:
sed -i 's/load printers = yes/load printers = no/g' /etc/samba/smb.conf
cat >>/etc/samba/smb.conf<< EOF
[财务部]
comment = caiwu
path = /share/caiwu
public = no
writeable = yes
valid users = @caiwu,zhuohua
read list = @caiwu
write list = c1,zhuohua
EOF
cat >>/etc/samba/smb.conf<< EOF
[市场部]
comment = shichang
path = /share/shichang
public = no
writeable = yes
valid users = @shichang,zhuohua
read list = @shichang
write list = s1,zhuohua
EOF
cat >>/etc/samba/smb.conf<< EOF
[public]
comment = public
path = /share/public
public = no
writeable = yes
valid users = @shichang,@caiwu,zhuohua
read list = @shichang,@caiwu
write list = zhuohua
EOF
修改完配置文件后,必须重启Samba服务:
[root@localhost ~]# service smb restart
关闭 SMB 服务: [确定]
启动 SMB 服务: [确定]
加上任务计划:
[root@localhost ~]# crontab -e
加上:
*/1 * * * * chmod -R 777 /share/
Windows客户机访问Samba服务器:(一个Samba用户可以同时在多台电脑登录)
笺注:实验中Samba服务器IP为 192.168.168.130
[attach]7750[/attach]
[attach]7751[/attach]
[attach]7752[/attach]
[size=6]实验达到要求 ^_^ ^_^[/size]
Windows客户端清空登录记录: [color=Blue]net use * /del[/color]
[attach]7753[/attach]
再次访问共享,就要重新输入帐号、密码:
[attach]7754[/attach]
[attach]7755[/attach]
要是不想显示用户的宿主目录,可以修改配置文件,把下面6行代码删除即可
[attach]7756[/attach]
修改了配置文件后,记得重新启动Samba服务:
[root@localhost ~]# service smb restart
关闭 SMB 服务: [确定]
启动 SMB 服务: [确定]
效果:
[attach]7757[/attach]
修改Samba用户的密码:
[attach]7758[/attach]
锁定Samba用户:(用户无法访问共享)
[attach]7759[/attach]
解锁Samba用户:
[attach]7760[/attach]
删除Samba用户:
[attach]7761[/attach]
相关文章:
[url=http://blog.zhuohua.store/viewthread.php?tid=244&page=1&extra=#pid247]用户管理[/url]
[url=http://blog.zhuohua.store/viewthread.php?tid=93&extra=page%3D1]Samba匿名共享[/url]
[url=http://blog.zhuohua.store/viewthread.php?tid=95&page=1&extra=#pid96]Samba用户验证(二)[/url]
[url=http://blog.zhuohua.store/viewthread.php?tid=388&extra=page%3D1]CentOS8_Samba用户验证[/url]
[url=http://blog.zhuohua.store/viewthread.php?tid=540&page=1&extra=#pid968]CentOS8_在Docker中安装Samba[/url]
[url=http://blog.zhuohua.store/viewthread.php?tid=96&extra=page%3D1]Windows2008r2_文件共享[/url]
页:
[1]