先ping通网络
[root@localhost ~]# ping www.baidu.com
到home创建需要共享目录和文件
[root@localhost /]# cd /home/
[root@localhost home]# ls
zms
[root@localhost home]# mkdir aa
[root@localhost home]# cd aa/
[root@localhost aa]# touch aa.txt
[root@localhost aa]# ls
aa.txt
[root@localhost aa]# cd ..
[root@localhost home]# chmod 777 aa
安装samba
[root@localhost home]# yum install samba -y
在home创建用户组和用户
[root@localhost home]# groupadd aa(用户组aa)
[root@localhost home]# useradd -g aa s1(在aa用户组创建用户s1)
[root@localhost home]# passwd s1(设置用户密码)
Changing password for user s1.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost home]# useradd -g aa s2
[root@localhost home]# passwd s2
Changing password for user s2.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost home]# smbpasswd -a s1(把s1用户加入samba用户)
New SMB password:
Retype new SMB password:
Added user s1.
[root@localhost home]# smbpasswd -a s2
New SMB password:
Retype new SMB password:
Added user s2.
[root@localhost home]# ls
aa s1 s2 zms
修改配置文件smb.conf
[root@localhost aa]# cd /etc/samba/
[root@localhost samba]# ls
lmhosts smb.conf smb.conf.example
[root@localhost samba]# vi smb.conf
[aa]
path=/home/aa #共享文件路径
read only=no #可写可读
valid users=s1,s2 #共享用户
设置宽容模式,关闭防火墙
[root@localhost samba]# setenforce 0
[root@localhost samba]# systemctl stop firewalld.service
重启samba服务并用ip到cmd窗口测试(窗口测试:Ctrl右边的田键+R)
[root@localhost samba]# systemctl restart smb
[root@localhost samba]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:15:7e:d0 brd ff:ff:ff:ff:ff:ff
inet 192.168.159.144/24 brd 192.168.159.255 scope global dynamic ens32
valid_lft 1715sec preferred_lft 1715sec
inet6 fe80::ae93:5079:ff3d:3d02/64 scope link
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
link/ether 52:54:00:a4:bb:b7 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
link/ether 52:54:00:a4:bb:b7 brd ff:ff:ff:ff:ff:ff
关闭文件夹,并到cmd以下命令在执行虚拟账号
net use * /del
虚拟账号
[root@localhost samba]# ls
lmhosts smb.conf smb.conf.example
[root@localhost samba]# vi smbuses(新建smbuses文件加入虚拟账号)
(注意:smbuses文件可以是其他名字,但是在下面配置映射的路径要名字一致)
s1=map1 map2 map3 #map虚拟账号
s2=map4 map5
[root@localhost samba]# vi smb.conf (添加下面加粗的映射路径)
username map=/etc/samba/smbuses
重启smb在次用ip验证
[root@localhost samba]# systemctl restart smb
用虚拟账号登录
掩藏文件
[root@localhost samba]# touch smb.conf.s1(创建smb.conf.s1)
[root@localhost samba]# vi smb.conf
在里面添加config file=/etc/samba/smb.conf.%U(当前用户可见)
修改
为(不可见)
[root@localhost samba]# vi smb.conf.s1 (添加一下5行。注意自己的路径)
[global]
security=user
[aa]
path=/home/aa
browseable=yes
[root@localhost samba]# systemctl restart smb
开始用不同的用户访问
注意:我们设置的是s1用户可见s2用户不可见,我们用s2登录看不见共享目录aa所以就成功了