1.应用场景,搭建sam共享目录
可用于linux以及windows之间


2.服务端ip:192.168.56.11 (A)
客户端ip:192.168.56.133 (B)


查看防火墙状态并关闭

[root@guohui ~]#systemctl status firewalld
[root@guohui ~]#systemctl disable firewalld

[root@guohui ~]#systemctl stop firewalld
[root@guohui ~]#setenforce 0

先安装sam,并设置sam用户

[root@guohui ~]# yum -y install samba-*   
[root@guohui ~]# useradd -M DDD     //创建用户DDD,-M,不建立用户家目录
[root@guohui ~]# smbpasswd -a DDD      //添加系统用户为samba用户并设置密码123
New SMB password:
Retype new SMB password:
Added user DDD.
testparm

[root@guohui samba]# touch smbusers    //在 /etc/samba下创建/smbusers
[root@guohui samba]# echo 'DDD = share' > /etc/samba/smbusers       //这里要将映射DDD为share用户,需在/etc/samba/smbusers 文件中添加 DDD = share
//映射后用户DDD将会变成share用户身份,也就像是人带着面具

[root@guohui samba]# vim /etc/samba/smb.conf         //在全局配置中添加如下
[global]
    workgroup = SAMBA
    security = user
        username map = /etc/samba/smbusers                    //添加用户名映射文件 /etc/samba/smbusers

[root@guohui ~]# mkdir /opt/guohui
[root@guohui ~]# chown -R DDD.DDD /opt/guohui

[root@guohui ~]# testparm                     //测试配置文件是否有语法错误,查看最终生效的配置
Load smb config files from /etc/samba/smb.conf

[root@guohui ~]# ll /opt/
总用量 0
drwxr-xr-x. 2 DDD  DDD  6 8月   6 17:07 guohui

//配置共享
[root@guohui ~]# cat >> /etc/samba/smb.conf <<EOF

> [guohui]                             //目录名
> comment = guohui           //注释
> path = /opt/guohui            //路径
> browseable = yes            //允许浏览
> guest ok = yes                 //允许所有人访问
> writable = yes                  //可写的
> write list = share              //可写 身份 share  ,用来限定上一条,如不指定,则所有用户都能写
> public = yes                     //公开的,允许任何账户包括无账户口令,no则需要合法账户才能访问资源
> EOF

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

``

[root@guohui ~]# systemctl start smb                //启动smb服务
[root@guohui ~]# systemctl restart smb             //重启smb服务
[root@guohui ~]# systemctl reload smb             //重新加载smb服务
[root@guohui ~]# systemctl enable smb             //设置smb服务随系统启动而启动
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.

//在客户机查看samba服务器有那些共享资源 (B)

[root@guohui ~]# smbclient -L 192.168.56.11 -U share
Enter SAMBA\share's password:
Anonymous login successful
OS=[Windows 6.1] Server=[Samba 4.7.1]

    Sharename       Type      Comment
    ---------       ----      -------
    print$          Disk      Printer Drivers
    guohui          Disk      guohui
    IPC$            IPC       IPC Service (Samba 4.7.1)
Anonymous login successful
OS=[Windows 6.1] Server=[Samba 4.7.1]

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------            -------

//将samba服务器的共享资源guohui挂载到客户机本地 (B)
以cifs的方式将IP地址以DDD身份挂载到

[root@guohui ~]# mkdir -p /opt/guohui
[root@guohui ~]#  mount -t cifs //192.168.56.11/guohui /opt/guohui/ -o username=share,password=123
[root@guohui ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
tmpfs                     98M     0   98M    0% /run/user/0
//192.168.56.11/guohui    17G  4.0G   14G   24% /opt/DDD

[root@guohui opt]# cd guohui           (B)在目录下创建
[root@guohui guohui]# mkdir 1

[root@guohui ~]# ls /opt/guohui        (A)验证
1

总结,请务必先关闭防火墙


2.如何配置匿名共享



查看防火墙状态并关闭
[root@guohui ~]# systemctl status firewalld
[root@guohui ~]# systemctl disable firewalld
[root@guohui ~]# systemctl stop firewalld
[root@guohui ~]# setenforce 0
//使用yum安装samba服务器

[root@guohui ~]# yum -y install samba-*   
//在全局配置中添加

[root@guohui ~]# vim /etc/samba/smb.conf     
[global]
        workgroup = SAMBA
        security = user
        map to guest = Bad User        //添加本行命令,固定式

//创建一个共享目录

[root@guohui ~]# mkdir /opt/guohui1
[root@guohui ~]# chmod 777 /opt/guohui1
[root@guohui ~]# ll /opt/
drwxrwxrwx. 2 root root 6 8月   6 19:45 guohui1

//配置共享

[root@guohui ~]# vim /etc/samba/smb.conf
[root@guohui ~]# tail -7 /etc/samba/smb.conf
[guohui1]
comment = guohui1
path = /opt/guohui1
browseable = yes
guest ok = yes
writable = yes
public = yes
//启动smb服务

[root@guohui ~]#  systemctl start smb

//在客户机查看samba服务器的共享资源,发现guohui1 //(B)

[root@guohui ~]# smbclient -L 192.168.56.11 -U 'Bad User'
Enter SAMBA\Bad User's password:
OS=[Windows 6.1] Server=[Samba 4.7.1]

Sharename       Type      Comment
---------       ----      -------
print$          Disk      Printer Drivers
guohui1         Disk      guohui1
IPC$            IPC       IPC Service (Samba 4.7.1)

//将samba服务器的共享资源guohui1挂载到客户机本地

[root@guohui ~]# mkdir -p /opt/guohui1
[root@guohui ~]# mount -t cifs //192.168.56.11/guohui1 /opt/guohui1/ -o username='Bad User'
Password for Bad User@//192.168.56.11/guohui1:              //空格

[root@guohui ~]# df -h
//192.168.56.11/guohui1   17G  4.0G   14G   24% /opt/guohui1

//在客户机上进入共享目录创建新文件

[root@guohui ~]# cd /opt/guohui1          (B)在目录下创建
[root@guohui guohui1]# mkdir 1
//samba服务器验证

[root@guohui ~]# ls /opt/guohui1        (A)验证
1

总结:



//使用windows登陆samba服务器,用户(Bad User),无需密码

1.放置windows里的文件到samba服务器里 // 在windows系统里 (\+ip)登陆

samba共享显示没有目录_服务器

2.放置有一个window文件进入samba服务器,并使用samba服务器查看

[root@guohui guohui1]# mkdir 1
[root@guohui guohui1]# ls
1  1.txt


转载于:https://blog.51cto.com/13859004/2155835