how to install and setup samba on centos:

tested with:

hostnamectl
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7

Kernel: Linux 3.10.0-693.21.1.el7.x86_64

yum info samba.x86_64
Version : 4.6.2
Release : 12.el7_4
Size : 1.8 M
Repo : installed
From repo : updates
Summary : Server and Client software to interoperate with Windows machines
URL : http://www.samba.org/
License : GPLv3+ and LGPLv3+
Description : Samba is the standard Windows interoperability suite of programs for Linux and
: Unix.

yum install samba samba-client samba-common; # install samba

# let samba through firewall
firewall-cmd --permanent --zone=public --add-service=samba
firewall-cmd --reload

# make service autostart
systemctl enable smb.service
systemctl enable nmb.service

# start service
systemctl start smb.service
systemctl start nmb.service

# add a general group, for group-based access
groupadd smbgrp

# add user
# add user to system
useradd -m user
# give user a systemwide password
passwd user
usermod user -aG smbgrp; # add user to samba group
smbpasswd -a user; # set smb password

# add user's private share
mkdir -p /srv/samba/user;
chmod -R 0770 /srv/samba/user;
chown -R root:smbgrp /srv/samba/user;
chcon -t samba_share_t /srv/samba/user;

vim /etc/samba/smb.conf

[global]
workgroup = WORKGROUP
netbios name = centos
security = user

[user]
comment = Secure File Server Share
path =  /srv/samba/user
valid users = @smbgrp
guest ok = no
writable = yes
browsable = yes

:wq # save and quit vim

testparm; # test samba config

# restart service
systemctl restart smb.service;
systemctl restart nmb.service;

now you can fire up your windows workstation that needs to be in the same WORKGROUP as specify under global in smb.cnf

let’s make this easier by a script

download here.add_new_samba_user_and_share.sh.txt

vim /scripts/add_new_samba_user_and_share.sh

#!/bin/bash

if [ $# -eq 0 ]
  then
    echo "please give a username. No arguments supplied."
    exit;
fi

useradd -m $1
passwd $1
usermod $1 -aG smbgrp
smbpasswd -a $1; # set smb password

# add user's private share
mkdir -p /srv/samba/$1;
chmod -R 0770 /srv/samba/$1;
chown -R root:smbgrp /srv/samba/$1;
chcon -t samba_share_t /srv/samba/$1;

echo "
 
[$1]
comment = Secure File Server Share of $1
path =  /srv/samba/$1
valid users = $1
guest ok = no
writable = yes
browsable = yes
" >> /etc/samba/smb.conf;

testparm; # test samba config

# restart service
systemctl restart smb.service;
systemctl restart nmb.service;

:wq # save and quit vim

chmod +x /scripts/*.sh; make it executable and give it a practice run

 

additional stuff:

# delet a samba user
pdbedit -x -u username

# info about samba

yum info samba
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.fra10.de.leaseweb.net
 * epel: mirror.23media.de
 * extras: centos.copahost.com
 * updates: ftp.rz.uni-frankfurt.de
Installed Packages
Name        : samba
Arch        : x86_64
Version     : 4.6.2
Release     : 12.el7_4
Size        : 1.8 M
Repo        : installed
From repo   : updates
Summary     : Server and Client software to interoperate with Windows machines
URL         : http://www.samba.org/
License     : GPLv3+ and LGPLv3+
Description : Samba is the standard Windows interoperability suite of programs for Linux and
            : Unix.

[root@privat scripts]# smbstatus --version
Version 4.6.2
admin