How To Samba Server Installation and Configuration in CentOS 6.5

Samba is used to allow users to share and use files, folders and printers between Linux and Windows systems. In this how-to tutorial let us see how to install and configure samba server.

Scenario

In this tutorial, i use two systems as described below

Samba server:

Operating system : CentOS 6.5
Hostname : server.geniusansh.com
IP Address : 192.168.0.155/24

Samba client:

Operating system : Windows 7 Ultimate
Hostname : client
IP Address : 192.168.0.129/24

Install Samba package

Check and remove any previously installed samba package
[root@server ~]# rpm -qa | grep samba
[root@server ~]# yum list installed | grep samba
If it installed, remove it using the below command
[root@server ~]# yum remove samba*
Now install samba
[root@server ~]# yum install samba* -y

Configure a fully accessed anonymous share

Create a directory called ‘/samba/share1′ and set full permission
[root@server ~]# mkdir -p /samba/share1
[root@server ~]# chmod -R 0777 /samba/share1/
Edit and add the following lines in samba config file as shown below
[root@server ~]# vi /etc/samba/smb.conf

## Line no 58 - Add the following lines below line 58 ##
unix charset = UTF-8
dos charset = CP932
## Line no 75 - Change the to windows default workgroup ##
workgroup = WORKGROUP
## Line no 81 - Uncomment and set the IP Range ##
hosts allow = 127. 192.168.0.
## Line 102 - set no authentication ##
security = share
## Add the following lines at the bottom ##
[myshare]
path = /samba/share1
writable = yes
browsable = yes
guest ok = yes
guest only = yes
create mode = 0777
directory mode = 0777

Start samba server
[root@server ~]# vi /etc/samba/smb.conf
[root@server ~]# /etc/init.d/smb start
Starting SMB services: [ OK ]
[root@server ~]# /etc/init.d/nmb start
Starting NMB services: [ OK ]
[root@server ~]# chkconfig smb on
[root@server ~]# chkconfig nmb on
Test the Samba server
We can test the Samba server configuration using the command ‘testparm’.
[root@server ~]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[myshare]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

[global]
dos charset = CP932
server string = Samba Server Version %v
security = SHARE
log file = /var/log/samba/log.%m
max log size = 50
hosts allow = 127., 192.168.0.
cups options = raw

[homes]
comment = Home Directories
read only = No
browseable = No

[printers]
comment = All Printers
path = /var/spool/samba
printable = Yes
browseable = No

[myshare]
path = /samba/share1
read only = No
create mask = 0777
directory mask = 0777
guest only = Yes
guest ok = Yes

Allow Samba server through firewall
[root@server ~]# vi /etc/sysconfig/iptables

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -s 192.168.1.0/24 -m state --state NEW -p udp --dport 137 -j ACCEPT
-A INPUT -s 192.168.1.0/24 -m state --state NEW -p udp --dport 138 -j ACCEPT
-A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 139 -j ACCEPT
-A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 445 -j ACCEPT
-A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 901 -j ACCEPT
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
Restart iptables to save the changes
[root@server ~]# service iptables restart
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
Disable SELINUX
[root@server ~]# vi /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
Restart the server and goto windows client system
Click Start -> Run. Enter the samba Server IP as shown below.
Now create some folders and files
Check whether the newly created files or folders present in the samba server

Configure a authenticated share using samba server

Create a user called “ansh” and a group called “anshgroup”. Add the user “ansh” to the group “anshgroup”
[root@server ~]# useradd ansh
[root@server ~]# groupadd anshgroup
[root@server ~]# usermod -a -G anshgroup ansh
[root@server ~]# smbpasswd -a ansh
New SMB password:
Retype new SMB password:
Added user ansh.
Create a new share called “/samba/share2″ and set the permissions to that share.
[root@server ~]# mkdir /samba/share2
[root@server ~]# chmod -R 0755 /samba/share2/
[root@server ~]# chown -R sk:anshgroup /samba/share2/
Add the below lines at the bottom of samba config file.
[root@server ~]# vi /etc/samba/smb.conf
[secure]
path = /samba/share2
writable = yes
browsable = yes
guest ok = no
valid users = @anshgroup
Test the configuration for any errors
[root@server ~]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[myshare]"
Processing section "[secure]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

[global]
dos charset = CP932
server string = Samba Server Version %v
security = SHARE
log file = /var/log/samba/log.%m
max log size = 50
hosts allow = 127., 192.168.0.
cups options = raw

[homes]
comment = Home Directories
read only = No
browseable = No

[printers]
comment = All Printers
path = /var/spool/samba
printable = Yes
browseable = No

[myshare]
path = /samba/share1
read only = No
create mask = 0777
directory mask = 0777
guest only = Yes
guest ok = Yes

[secure]
path = /samba/share2
valid users = @anshgroup
read only = No
Restart samba server
[root@server ~]# /etc/init.d/smb restart
Shutting down SMB services: [ OK ]
Starting SMB services: [ OK ]
[root@server ~]# /etc/init.d/nmb restart
Shutting down NMB services: [ OK ]
Starting NMB services: [ OK ]
Now goto windows client and try to access the secured share.

Configure samba server in GUI mode

If you struggle with command line configuration, you can configure samba server in GUI mode too using “samba-swat” package. I prefer and suggest you command line mode only.
Install the “samba-swat” package if it is not installed.
[root@server ~]# yum install xinetd samba-swat -y


Configure SWAT

Open the “samba-swat” config file and edit as shown below
[root@server ~]# vi /etc/xinetd.d/swat
# default: off
# description: SWAT is the Samba Web Admin Tool. Use swat \
# to configure your Samba server. To use SWAT, \
# connect to port 901 with your favorite web browser.
service swat
{
port = 901
socket_type = stream
wait = no
only_from = 127.0.0.1 192.168.0.0/24
user = root
server = /usr/sbin/swat
log_on_failure += USERID
disable = no
}
Restart samba and xinetd services
[root@server ~]# /etc/init.d/xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[root@server ~]# /etc/init.d/smb restart
Shutting down SMB services: [ OK ]
Starting SMB services: [ OK ]
[root@server ~]# /etc/init.d/nmb restart
Shutting down NMB services: [ OK ]
Starting NMB services: [ OK ]
Open the web browser from any client syatems. In the address bar type http://server-ip-address:901 and press enter. Now the console screen will open. You can start configure samba server here.
That's IT. Enjoy with SMB!!!

Comments

Popular Posts