How to install and configure Samba in CentOS / RHEL?

To provide printer and file sharing, Microsoft Windows uses a facility known as SMB (Server Message Block). This same facility is sometimes known as NetBIOS or LanManager. Thanks to Andrew Tridgell and others, Linux systems provide support for SMB via a package known as Samba. Like SMB, Samba lets you:

  • Share printers and files among Microsoft Windows, OS/2, Netware, and Unix systems
  • Establish a simple nameserver for identifying systems on your local area network
  • Backup PC files to a Linux system and restore them
  • Administer users and passwords

 

Samba has proven its reliability and high performance in many organizations. Samba software suite on Enterprise Linux is a collection of programs that implements the Server Message Block (commonly abbreviated as SMB) protocol for UNIX systems.

 

Installing Samba

 

In Enterprise Linux system, install below packages to get started with Samba. You can download/install these packages from the yum server using the “yum install” command.

samba       #### basic Samba packages
samba-client       #### samba client

 

To install these packages :

# yum install samba
# yum install samba-client

 

If you are using an active directory setup, install below packages as well.

# yum install samba-winbind
# yum install samba-winbind-clients
# yum install samba-winbind-krb5-locator

 

Below is the list of packages which will be installed once you have installed the above packages.

samba-libs
samba-winbind-krb5-locator
samba-winbind-modules
samba-vfs-glusterfs
samba-winbind
samba-client
samba-common
samba-winbind-clients
samba

 

Configuring a Samba share

 

Samba’s configuration usually resides in /etc/samba/smb.conf which contains all the configuration parameters related to samba. Follow the steps given below to configure a samba share.

 

1. For the share to be accessible to a particular user, we must first create a user (Zach) on the Linux server where the share resides as well.

# useradd zach

 

# passwd zach
Changing password for user zach.
New password: Retype new password: passwd: all authentication tokens updated successfully.

 

2. To add activate the Samba user and set the password, use the “smbpasswd” command with the -a option.

# smbpasswd -a zach

 

3. Create the directory to share or you can use an existing directory. Also, set full permissions on the directory.

# mkdir -p  /path/to/share
# chmod -R 777 /path/to/share

 

4. Next, set the SElinux contexts on the share. Verify if you can create a file in the share.

# chcon -R -t samba_share_t /path/to/share
# cd /path/to/share
# echo test > testfile.txt

 

5. Edit the /etc/samba/smb.conf file and add the share settings.

# vi /etc/samba/smb.conf
[share_name]
    path = /path/to/share
    comment = samba share for zach
public = yes writable = yes create mask = 0777 browseable = yes

 

Restart samba service for the above settings to take effect.

# service smb restart

 

Troubleshooting

 

To find out the issue with a samba share, you can try disabling the iptables service and turning off the SELinux. Make sure to enable them back after you resolve the conflict.

# service iptables stop
# setenforce 0

 

Verify samba parameter using testparm 

To verify that the parameters are correct in the smb.conf file or to debug configuration problems, use the testparm command.

 

logs

For debugging problems with Samba in general, the log files log.smbd and log.nmbd under the /var/log/samba directory are invaluable. The parameter log level in the global section of the smb.conf file determines the amount of detailed information Samba writes to the log files, with level 0 being the most general and 10 being the most detailed. Each logging level contains the messages from that level, in addition to the logging messages below it. For example, a logging level of 5 contains messages from level 5, plus those from levels 0 through 4.

# vi /etc/samba/smb.conf
# this tells Samba to use a separate log file for each machine
# that connects
log file = /var/log/samba/%m.log
debuglevel = 4

 

Was this answer helpful? 0 Users Found This Useful (0 Votes)