CentOS 7.2 安装配置Samba服务器

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

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

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

2环境

CentOS系统

[root@linuxidc.com ~]# cat /etc/RedHat-release CentOS Linux release 7.2.1511 (Core)

Samba服务器

[root@linuxidc.com ~]# 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:// 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安装

[root@base ~]# yum -y install samba samba-client

4配置

进入samba配置目录

[root@base ~]# cd /etc/samba/

备份smb.conf

[root@base samba]# mv smb.conf smb.conf.origin

新建smb.conf

[root@base 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上在这个目录下新建的文件会有“可执行”属性)

创建用户

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

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

创建共享目录

[root@base samba]# mkdir -p /smb/{fileshare,webdev} [root@base samba]# chown nobody:nobody /smb/fileshare/ [root@base samba]# chown ted:co3 /smb/webdev/

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

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

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

开放端口

[root@base samba]# firewall-cmd --permanent --add-port=139/tcp success [root@base samba]# firewall-cmd --permanent --add-port=445/tcp success [root@base samba]# systemctl restart firewalld [root@base samba]#

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

5使用 本机测试

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

[root@base 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 [root@base samba]#

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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/c19931eb4bbe2a81343f98d4ce2df0e3.html