linux——如何搭建samba共享目录中的,用户认证共享及匿名用户共享?(不分系统)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux——如何搭建samba共享目录中的,用户认证共享及匿名用户共享?(不分系统)相关的知识,希望对你有一定的参考价值。

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


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


查看防火墙状态并关闭

[[email protected] ~]#systemctl status firewalld
[[email protected] ~]#systemctl disable firewalld

[[email protected] ~]#systemctl stop firewalld
[[email protected] ~]#setenforce 0

先安装sam,并设置sam用户

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

[[email protected] samba]# touch smbusers    //在 /etc/samba下创建/smbusers
[[email protected] samba]# echo ‘DDD = share‘ > /etc/samba/smbusers       //这里要将映射DDD为share用户,需在/etc/samba/smbusers 文件中添加 DDD = share

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

[[email protected] ~]# mkdir /opt/guohui
[[email protected] ~]# chown -R DDD.DDD /opt/guohui

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

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

//配置共享
[[email protected] ~]# cat >> /etc/samba/smb.conf <<EOF

> [guohui]
> comment = guohui
> path = /opt/guohui
> browseable = yes
> guest ok = yes
> writable = yes
> write list = share
> public = yes
> EOF

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

``

[[email protected] ~]# systemctl start smb                //启动smb服务
[[email protected] ~]# systemctl restart smb             //重启smb服务
[[email protected] ~]# systemctl reload smb             //重新加载smb服务
[[email protected] ~]# 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)

[[email protected] ~]# smbclient -L 192.168.56.11 -U share
Enter SAMBAshare‘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身份挂载到

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

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

[[email protected] ~]# ls /opt/guohui        (A)验证
1

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


2.如何配置匿名共享



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

[[email protected] ~]# yum -y install samba-*   
//在全局配置中添加

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

//创建一个共享目录

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

//配置共享

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

[[email protected] ~]#  systemctl start smb

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

[[email protected] ~]# smbclient -L 192.168.56.11 -U ‘Bad User‘
Enter SAMBABad 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挂载到客户机本地

[[email protected] ~]# mkdir -p /opt/guohui1
[[email protected] ~]# mount -t cifs //192.168.56.11/guohui1 /opt/guohui1/ -o username=‘Bad User‘
Password for Bad [email protected]//192.168.56.11/guohui1:              //空格

[[email protected] ~]# df -h
//192.168.56.11/guohui1   17G  4.0G   14G   24% /opt/guohui1

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

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

[[email protected] ~]# ls /opt/guohui1        (A)验证
1

总结:



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

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

技术分享图片

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

[[email protected] guohui1]# mkdir 1
[[email protected] guohui1]# ls
1  1.txt

以上是关于linux——如何搭建samba共享目录中的,用户认证共享及匿名用户共享?(不分系统)的主要内容,如果未能解决你的问题,请参考以下文章

linux下实现文件共享:搭建samba服务器

Linux 搭建Samba(共享)服务

samba中设置共享目录步骤

Linux搭建Samba服务以供Windows用户使用

Linux搭建Samba服务以供Windows用户使用

Linux搭建Samba共享服务器