centos7 配置samba

栏目: 服务器 · 发布时间: 6年前

内容简介:##原理windows 和samba服务进行通信使用的是NETBIOS协议linux和linux 之间通信使用的是SMB协议
iptables -A INPUT -p tcp -m multiport --dport 139,445 -j ACCEPT

##原理

windows 和samba服务进行通信使用的是NETBIOS协议

linux和 linux 之间通信使用的是SMB协议

配置文件

[root@server samba]# cat 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 = myshare
    security = user
    map to guest = bad user
    passdb backend = tdbsam

    printing = cups
    printcap name = cups
    load printers = yes
    cups options = raw
[homes]  
    comment = Home Directories 
    valid users = %S, %D%w%S 
    browseable = No
    read only = No
    inherit acls = Yes

[printers]
    comment = All Printers
    path = /var/tmp
    printable = Yes
    create mask = 0600
    browseable = No

[print$]
    comment = Printer Drivers
    path = /var/lib/samba/drivers
    write list = root
    create mask = 0664
    directory mask = 0775
[share]
    path=/smbshare
    public=yes
    writable=yes
[share1]
    path=/smbu
    valid users = smbuser1,smbuser2,@g1
    writable=yes

配置匿名访问配置

[global]
        workgroup = myshare
        security = user
        map to guest = bad user # 添加此行
        passdb backend = tdbsam

        printing = cups
        printcap name = cups
        load printers = yes
        cups options = raw

末尾曾加

[share]
        path = /smbshare
        public = yes
        writable=yes

重启

[root@localhost ~]# systemctl enable smb nmb # smb是Linux和Linux之间的协议,nmb是Linux和Windows之间的协议
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/nmb.service to /usr/lib/systemd/system/nmb.service.

[root@localhost ~]# systemctl restart smb nmb

后面连接出错,请先关selinux 然后重启服务

客户端连接

[root@node-server-1 ~]# mount -t cifs //192.168.50.156/public /media/
mount: wrong fs type, bad option, bad superblock on //192.168.50.156/public,
       missing codepage or helper program, or other error
       (for several filesystems (e.g. nfs, cifs) you might
       need a /sbin/mount.<type> helper program)

       In some cases useful info is found in syslog - try
       dmesg | tail or so.

需要安装

yum -y install cifs-utils

windows连接

centos7 配置samba

然后再次连接

[root@desktop ~]# mount -t cifs //172.10.100.128/share /media/
Password for root@//172.10.100.128/share:
[root@desktop ~]# cd /media/
[root@desktop media]# ls
ls: reading directory .: Permission denied
[root@desktop media]#

添加用户

1.创建samba用户

[root@server samba]# useradd -s /sbin/nologin smbuser1
[root@server samba]# smbpasswd -a smbuser1
New SMB password:
Retype new SMB password:
Added user smbuser1.

配置文件假如 smbuser1

[share1]
    path=/smbu
    valid users = smbuser1
    writable=yes

挂载

mount -t cifs //172.10.100.128/share1 -o username=smbuser1 /mnt/u1/

设置开机启动

[root@desktop mnt]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Sat May  6 22:20:05 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=8567c1db-cc09-442e-83ce-cfcdd1f8f0df /boot                   xfs     defaults        0 0
/dev/mapper/cl-swap     swap                    swap    defaults        0 0
//172.10.100.128/share1 /mnt/u4 cifs defaults, username=smbuser1,password=123456 0 0

多用户设置

1.创建多个 Samba 用户

[root@server samba]# useradd -s /sbin/nologin smbuser2
[root@server samba]# smbpasswd -a smbuser2
New SMB password:
Retype new SMB password:
Added user smbuser2.
[root@server samba]# groupadd g1
[root@server samba]# useradd -s /sbin/nologin -g g1 smbu3
[root@server samba]# smbpasswd -a smbu3
New SMB password:
Retype new SMB password:
Added user smbu3.

2.配置文件修改为

[share1]
    path=/smbu
    valid users = smbuser1,smbuser2,@g1 //多个用户用,隔开,@代表组,这里表示组1
    writable=yes

3.客户端挂载

mount -t cifs //172.10.100.128/share1 -o username=smbuser1 /mnt/u1/
mount -t cifs //172.10.100.128/share1 -o username=smbuser2 /mnt/u2/
mount -t cifs //172.10.100.128/share1 -o username=smbu3 /mnt/u3/

4.配置文件多个用户共享

[root@desktop samba]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Sat May  6 22:20:05 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=8567c1db-cc09-442e-83ce-cfcdd1f8f0df /boot                   xfs     defaults        0 0
/dev/mapper/cl-swap     swap                    swap    defaults        0 0
//172.10.100.128/share1 /mnt/u4 cifs defaults,credentials=/smb.mount 0 0

创建一个文件

[root@desktop samba]# cat /smb.mount
username=smbuser1
password=123456
username=smbuser2
password=123456

挂载

[root@desktop samba]# mount -a
[root@desktop samba]# mount | tail -1
//172.10.100.128/share1 on /mnt/u4 type cifs (rw,relatime,vers=1.0,cache=strict,username=smbuser2,domain=SERVER,uid=0,noforceuid,gid=0,noforcegid,addr=172.10.100.128,unix,posixpaths,serverino,mapposix,acl,rsize=1048576,wsize=65536,echo_interval=60,actimeo=1)

故障处理

1.报错 Unable to find suitable address.

[root@client mnt]# mount -t cifs -o username=smb1  //172.10.100.129/share /mnt
Password for smb1@//172.10.100.129/share:  ******
Unable to find suitable address.

检查防火墙


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

近似算法

近似算法

瓦齐拉尼 / 2010-9 / 49.00元

《近似算法》系统总结了到本世纪初为止近似算法领域的成果,重点关注近似算法的设计与分析,介绍了这个领域中最重要的问题以及所使用的基本方法和思想。全书分为三部分:第一部分使用不同的算法设计技巧给出了下述优化问题的组合近似算法:集合覆盖、施泰纳树和旅行商、多向割和k-割、k-中心、反馈顶点集、最短超字符串、背包、装箱问题、最小时间跨度排序、欧几里得旅行商等。第二部分介绍基于线性规划的近似算法。第三部分包......一起来看看 《近似算法》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试