CentOS 7.2 安装配置Samba服务器

1背景

转Linux刚刚1年,vim操作还不能应对工程代码,之前一直都是Gnome桌面 + Clion 作开发环境,无奈在服务器上没有这样的环境,

看同事是(Windows)Source Insight + WinSCP + Linux 开发,来回同步文件有点麻烦,所以想尝试搭个Samba服务器做共享文件。

不过希望以后还是要转到vim上来。

2环境

CentOS系统

[[email protected] ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core) 

Samba服务器

[[email protected] ~]# rpm -qi samba
Name        : samba
Epoch       : 0
Version     : 4.4.4
Release     : 9.el7
Architecture: x86_64
Install Date: Sun 18 Dec 2016 11:59:56 PM CST
Group       : System Environment/Daemons
Size        : 1869290
License     : GPLv3+ and LGPLv3+
Signature   : RSA/SHA256, Mon 21 Nov 2016 04:38:30 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : samba-4.4.4-9.el7.src.rpm
Build Date  : Mon 07 Nov 2016 06:31:03 PM CST
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.samba.org/
Summary     : Server and Client software to interoperate with Windows machines
Description :
Samba is the standard Windows interoperability suite of programs for Linux and
Unix.

3安装

[[email protected] ~]# yum -y install samba samba-client

4配置

进入samba配置目录

[[email protected] ~]# cd /etc/samba/

备份smb.conf

[[email protected] samba]# mv smb.conf smb.conf.origin

新建smb.conf

[[email protected] samba]# vim smb.conf

内容如下,保存并退出

[global]
        workgroup = WORKGROUP
        server string = Ted Samba Server %v
        netbios name = TedSamba
        security = user
        map to guest = Bad User
        passdb backend = tdbsam

[FileShare]
        comment = share some files
        path = /smb/fileshare
        public = yes
        writeable = yes        create mask = 0644        directory mask = 0755

[WebDev]
        comment = project development directory
        path = /smb/webdev
        valid users = ted
        write list = ted
        printable = no
        create mask = 0644
        directory mask = 0755

注释:

workgroup 项应与 Windows 主机保持一致,这里是WORKGROUP

security、map to guest项设置为允许匿名用户访问

再下面有两个section,实际为两个目录,section名就是目录名(映射到Windows上可以看见)。

第一个目录名是FileShare,匿名、公开、可写

第二个目录吗是WebDev,限定ted用户访问

默认文件属性644/755(不然的话,Windows上在这个目录下新建的文件会有“可执行”属性)

创建用户

[[email protected] samba]# groupadd co3
[[email protected] samba]# useradd ted -g co3 -s /sbin/nologin
[[email protected] samba]# smbpasswd -a ted
New SMB password:
Retype new SMB password:
Added user ted.
[[email protected] samba]# 

注意这里smbpasswd将使用系统用户。设置密码为1

创建共享目录

[[email protected] samba]# mkdir -p /smb/{fileshare,webdev}
[[email protected] samba]# chown nobody:nobody /smb/fileshare/
[[email protected] samba]# chown ted:co3 /smb/webdev/

注意设置属性,不然访问不了。

启动Samba服务,设置开机启动

[[email protected] samba]# systemctl start smb
[[email protected] samba]# systemctl enable smb
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
[[email protected] samba]# 

开放端口

[[email protected] samba]# firewall-cmd --permanent --add-port=139/tcp
success
[[email protected] samba]# firewall-cmd --permanent --add-port=445/tcp
success
[[email protected] samba]# systemctl restart firewalld
[[email protected] samba]# 

或者直接把防火墙关了也行。

5使用

Linux访问

可以使用testparm测试samba配置是否正确

[[email protected] samba]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[FileShare]"
Processing section "[WebDev]"
Loaded services file OK.
Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

# Global parameters
[global]
    netbios name = TEDSAMBA
    server string = Ted Samba Server %v
    map to guest = Bad User
    security = USER
    idmap config * : backend = tdb

[FileShare]
    comment = share some files
    path = /smb/fileshare
    guest ok = Yes
    read only = No

[WebDev]
    comment = project development directory
    path = /smb/webdev
    create mask = 0644

valid users = ted
    write list = ted
[[email protected] samba]# 

root用户的话,不用密码可直接查看samba服务器情况

[[email protected] samba]# smbclient -L localhost
Enter root‘s password:
Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.4.4]

    Sharename       Type      Comment
    ---------       ----      -------
    FileShare       Disk      share some files
    WebDev          Disk      project development directory
    IPC$            IPC       IPC Service (Ted Samba Server 4.4.4)
Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.4.4]

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

    Workgroup            Master
    ---------            -------
[[email protected] samba]# 

Windows访问

1)在Windwos资源管理器访问

访问路径里填上: \\${Samba服务器的IP} ,然后回车,可以看见共享的目录。

FileShare是可以匿名访问的,可以访问、新建、删除文件。

这里拖进去一个txt文件,可以在Linux上看见该文件。

2)映射网络驱动器

右边的WebDev目录是需要密码访问的

这里演示一下映射该目录为网络驱动器。

“桌面” 右键单击“此电脑”,选择“映射网络驱动器”

在文件夹位置填写该共享文件的网络路径,这里是\\192.168.118.132\WebDev

勾选“使用其他凭据连接”,点“完成”。

填写用户密码

在我的电脑可以看见该网络驱动器(Y)

这里可以放源码工程,然后用Windows下的IDE打开、编辑,再在Linux编译、运行。

enjoy it~

以后有需求再补充Linux挂载samba共享目录、权限配置等等。

6参考文献

Linux Samba服务器配置

CentOS7安装配置SAMBA服务器

CentOS7下Samba的安装与配置

配置samba服务器,中加入了security=share,但是testparm输出的信息里没有这一条,客户机也无法访问

smb服务器目录和文件权限设置

时间: 2024-08-02 02:50:57

CentOS 7.2 安装配置Samba服务器的相关文章

CentOS 7.3 安装配置Samba服务器

1背景 转到Linux有段时间了,vim操作还不能应对工程代码,之前一直都是Gnome桌面 + Clion 作开发环境,无奈在服务器上没有这样的环境, 看同事是(Windows)Source Insight + WinSCP + Linux 开发,来回同步文件有点麻烦,所以想尝试搭个Samba服务器做共享文件. 不过希望以后还是要转到vim上来. 2环境 CentOS系统 [[email protected] ~]# cat /etc/RedHat-release CentOS Linux re

CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL)

CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL) 一.准备篇: 1 /etc/init.d/iptables stop #关闭防火墙 2 关闭SELINUX 3 vi /etc/selinux/config 4 #SELINUX=enforcing #注释掉 5 #SELINUXTYPE=targeted #注释掉 6 SELINUX=disabled #增加 7 :wq 8 shutdown -r now #重启系统 二.安装篇 1.安装nginx 1 yum re

CentOS 7.0安装配置Vsftp服务器步骤详解

安装Vsftp讲过最多的就是在centos6.x版本中了,这里小编看到有朋友写了一篇非常不错的CentOS 7.0安装配置Vsftp服务器教程,下面整理分享给各位. 一.配置防火墙,开启FTP服务器需要的端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止

CentOS 7.0安装配置LAMP服务器(Apache+PHP+MariaDB)

原文 CentOS 7.0安装配置LAMP服务器(Apache+PHP+MariaDB) 一.配置防火墙,开启80端口.3306端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机启动 2.安装iptables防火墙 yum insta

CentOS 7.0 安装配置LAMP服务器方法(Apache+PHP+MariaDB)

一.配置防火墙,开启80端口.3306端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机启动 2.安装iptables防火墙 yum install iptables-services #安装 vi /etc/sysconfig/ip

CentOS 6.6安装配置LAMP服务器(Apache+PHP5+MySQL)

准备篇: CentOS 6.6系统安装配置图解教程 http://www.osyunwei.com/archives/8398.html 1.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

CentOS 6.3安装配置LAMP服务器(Linux+Apache+MySQL+PHP5)

服务器系统环境:CentOS 6.3 客户端系统环境:Windows 7 ultimate(x86)sp1 简体中文旗舰版 ※  本文档描述了如何在Linux服务器配置Apache.Mysql.PHP5 LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的Web框架,该框架包括:Linux操作系统,Apache网络服务器,MySQL数据库,Perl.PHP或者Python编程语言,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流行的商业应用都是采取这个架构,和

CentOS 6.4安装配置LAMP服务器

CentOS 6.4安装配置LAMP服务器 (Apache+PHP5+MySQL) 2013年03月12日 ? LAMP ? 评论数 10 ? 被围观 14,290次+ 准备篇: 1.配置防火墙,开启80端口.3306端口   vi /etc/sysconfig/iptables   -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT   #允许80端口通过防火墙   -A INPUT -m state --state

CentOS安装配置Samba服务器

假设我们有这样一个场景 共享名     路径         权限 SHAREDOC   /smb/docs    所有人员包括来宾均可以访问 RDDOCS     /smb/tech    仅允许特定组的用户进行读写访问 特定组的组名为RD,目前的有quwenzhe.zhanghongjie两个人 1.安装Samba  yum -y install samba samba-client samba-common 2.创建共享目录(假设共享/smb目录下的文件) # mkdir -p /smb/