smb服务配置详解

配置用户共享用户

环境说明

服务端IP 客户端IP
192.168.24.248 192.168.24.145

在服务端操作如下

1.环境准备

关闭防火墙和selinux

[root@linfan ~]systemctl disable firewalld
[root@linfan ~]systemctl stop firewalld
[root@linfan ~]sed -ri '#^SELINUX=#cSELINUX=Disabled' /etc/selinux/config
[root@linfan ~]setenforce 0

2.安装samba服务器:

  yum -y install samba-*

3.共享用户配置

 useradd -M lin

为用户lin创建smb共享密码

 smbpasswd -a lin

将lin用户映射为share用户:

 echo 'lin = share' > /etc/samba/smbusers

在全局变量中添加如下内容:

[root@linfan ~]# vi /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
        username = /etc/samba/smbusers  //在此添加

4. 创建一个共享目录lin

[root@linfan ~]# mkdir -p /opt/lin/
[root@linfan ~]# chown -R lin.lin /opt/lin/

5.配置共享

[root@linfan ~]# cat >> /etc/samba/smb.conf <<EOF
> [lin]
> comment = lin
> path = /opt/lin
> browseable = yes
> guest ok = yes
> writable = yes
> write list = share 
> public = yes
> EOF
[root@linfan ~]# tail -8 /etc/samba/smb.conf
[lin]
comment = lin
path = /opt/lin
browseable = yes
guest ok = yes
writable = yes
write list = share 
public = yes

6.smb服务配置

启动smb服务

[root@linfan ~]# systemctl start smb

重启smb服务

[root@linfan ~]# systemctl restart smb

重新加载smb服务

[root@linfan ~]# systemctl reload smb

设置smb开机自启动

[root@linfan ~]# systemctl enable smb

在客户端操作

1.查看smb服务器共享了哪些资源

[root@linfan ~]# smbclient -L 192.168.24.248 -U share

2.创建挂载目录

[root@linfan ~]# mkdir -p /opt/smb/

3.将smb服务器上的lin挂载到本地

[root@linfan ~]# mount -t cifs //192.168.24.248/lin /opt/smb -o username=share,password=1

[root@linfan ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   17G  6.0G   12G  35% /
devtmpfs                 478M     0  478M   0% /dev
tmpfs                    489M     0  489M   0% /dev/shm
tmpfs                    489M  6.9M  482M   2% /run
tmpfs                    489M     0  489M   0% /sys/fs/cgroup
/dev/sda1               1014M  125M  890M  13% /boot
tmpfs                     98M     0   98M   0% /run/user/0
/dev/sr0                 4.3G  4.3G     0 100% /mnt
//192.168.24.248/lin      17G  6.0G   12G  36% /opt/smb

4.进入客户端共享目录创建新文件

[root@linfan opt]# cd /opt/smb

[root@linfan smb]# mkdir l
[root@linfan smb]# touch k
[root@linfan smb]# ls
k  l

5.在服务端验证

[root@linfan ~]# cd /opt/lin
[root@linfan lin]# ls
k  l

匿名用户共享

环境说明

服务端IP 客户端IP
192.168.24.248 192.168.24.146

在服务端操作如下

1.环境准备

关闭防火墙和selinux

[root@linfan ~]systemctl disable firewalld
[root@linfan ~]systemctl stop firewalld
[root@linfan ~]sed -ri '#^SELINUX=#cSELINUX=Disabled' /etc/selinux/config
[root@linfan ~]setenforce 0

2.安装smb服务

[root@linfan ~]# yum -y install samba-*  

3.编辑配置文件

[root@linfan ~]# vi /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
        map to guest = Bad User     //在此添加

4. 创建共享目录

[root@linfan ~]# mkdir /opt/doudou
[root@linfan ~]# chmod 777 /opt/doudou
[root@linfan ~]# ll /opt/
total 0
drwxrwxrwx. 2 root root   6 Aug  6 19:08 doudou
drwxr-xr-x. 8 root root 220 Jul 18 17:09 lin.d

5.编辑共享文件

[root@linfan ~]# cat >> /etc/samba/smb.conf <<EOF
> [doudou]
> comment = doudou
> path = /opt/doudou
> browseable = yes
> guest ok = yes
> writable = yes
> public = yes
> EOF
[root@linfan ~]# tail -7 /etc/samba/smb.conf
[doudou]
comment = doudou
path = /opt/doudou
browseable = yes
guest ok = yes
writable = yes
public = yes

6.启动smb服务


[root@linfan ~]# systemctl start smb 

7.在客户端查看smb服务共享 无需输入密码 直接回车即可

[root@linfan ~]# smbclient -L 192.168.24.248 -U'Bad User' 

8.创建挂载目录

[root@linfan ~]# mkdir -p /opt/smb

9.将smb服务器的共享文件doudou 挂载到本地客户端

[root@linfan ~]# mount -t cifs //192.168.24.248/doudou /opt/smb -o username='Bad User'
[root@linfan ~]# df -h  

10.切换到新的共享目录创建文件

[root@linfan ~]# cd /opt/smb
[root@linfan smb]# mkdir lin
[root@linfan smb]# touch wu
[root@linfan smb]# ls
lin  wu    

11.在服务端验证

[root@linfan doudou]# ls
lin  wu

猜你喜欢

转载自blog.51cto.com/13858192/2155437
SMB