Monday, April 15, 2013

How to configure samba in Linux

Step by step configure and using SAMBA server on Fedora using system-config-samba configuration tool.

   Samba is the utility for file and printer sharing for both Linux and Windows operating system.  In order to allow Windows user to access and grab files from your Linux Fedora Core system, you need to work on Samba server. 
  The procedure below show step by step to setup Samba sever (Samba File Sharing server) on Linux Fedora Core 6 using graphical configuration tool system-config-samba, this artile also show the step on how to use and access your share folder, files and printer that located on Linux Fedora Core system  from your Windows clients.

Backup Samba configuration files.

1. Backup all Samba configuration files.  The Samba configuration file usually located under /etc/samba directory, follow command below to backup the configuration file using 'cp' command.
[root@localhost ~]# cp -pr /etc/samba/ /etc/samba.bak
NOTE: Best practice; before you doing any configuration is to make an back on the original configuration files.

2. Verify the backup procedure.
[root@localhost ~]# ls /etc/samba [use double tab key here for command completion]
samba/ samba.bak/
[root@localhost ~]# ls /etc/samba

Open graphical Samba configuration tool.

1. Then open graphical samba configuration tool by pointing and click to System menu button (on the Panel bar) -> Administration -> Server Setting and click on Samba, or you can open the graphical Samba configuration tool using x-terminal (x-term/GNOME terminal) and type in 'system-config-samba'.
Figure: smb/samba_sml.png
samba server configuration
Figure: smb/samba_server_config.png above show the Samba Server Configuration (system-config-samba) tool window.

Samba server settings.

1.  Click on Preferences on the menu bar to open Server Setting window.
samba server settings
Figure: smb/server_setting.png
2.  In the Server settings window, on  the basic tab, you can setup or rename the samba Workgroup and short Description for the workgroup.  Make sure that the name of samba Workgroup did not match any Workgroups or any Domains on your network.
samba server setting basic tab
Figure: smb/server_setting_basic.png Samba Basic Server Setting example.
3. Then on the Security tab you can setup the configuration for:
Authentication Mode:
Authentication Server:
Kerberos Realm:
Encrypt Passwords:
Guest Account:
For the Authentication Mode, you can setup your samba server to:
ADS - Samba server act as a domain member in Active Directory domain.
Domain - Samba server relies for primary or backup domain controller to passes the username and password.
Server - Samba server verify the username and password on another samba sever, if fail then the samba server use the User authentication mode.
Share - Samba sever only prompt for username and password when only user connect to specific share directory.
User - User authentication mode (default setting), the samba user must provide username and password on a per samba server basis.
samba server settings security tab
Figure: smb/server_setting_security.png Samba Security Server Settings example.

Create Samba user.

   To enable user to access the files and printer share on the Samba Server you need to create user for Samba Server.  The step by step procedure below show how to add user to Samba Server using the graphical Samba Server Configuration tool,
1. To create samba user go to Preferences tab, then click on Samba Users to open the Samba Users window.
samba users
Figure: smb/samba_user.png
2.  On the Samba Users window, click Add User button to open the Create New Samba User window.
add samba user
Figure: smb/samba_users_1.png
3.  Provide the necessary information for samba user on Create New Samba User window.
Unix Username: Click and choose the username from local Fedora Core system user, you can add user to the list by using 'adduser' command.
Windows Username:  Provide the windows username for the samba user; make note that the Windows Username will be map with the Unix Username when user log in to the samba server.  Note: You can use same username for both Unix Username: and Windows Username:.
Samba Password:  Provide the password for samba user in order enable them to login to samba server.  Note: The password don't have to match the local Fedora Core user password neither the password from local user on Windows system.
Confirm Samba Password:  Retype the password.
Then click OK button to proceed.
create new samba user
Figure: smb/create_samba_user.png
4. The screenshot of list of Samba Users available on the system. Click OK button after done with the samba user creation.
list of samba users
Figure: smb/samba_users.png

Add Samba user using command line.

1.  Add local user on Fedora Core system.
[root@localhost samba]# adduser kimura
[root@localhost samba]#
[root@localhost samba]# passwd kimura
Changing password for user kimura.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@localhost samba]#
2.  Add samba user and samba password in smbpasswd.
[root@localhost samba]# smbpasswd -a kimura
New SMB password:
Retype new SMB password:
Added user kimura.
[root@localhost samba]#
3.  Verify and add user to the list of samba users (smbusers).
[root@localhost samba]# cat /etc/samba/smbusers
# Unix_name = SMB_name1 SMB_name2 ...
root = administrator admin
nobody = guest pcguest smbguest
veronica = veronica
[root@localhost samba]#
[root@localhost samba]# echo "kimura = kimura" >> /etc/samba/smbusers
[root@localhost samba]# cat /etc/samba/smbusers
# Unix_name = SMB_name1 SMB_name2 ...
root = administrator admin
nobody = guest pcguest smbguest
veronica = veronica
kimura = kimura
[root@localhost samba]#

Create Samba share directory.

1. Creating Samba share directory name 'smb_share' for all samba user in /home directory.  The command example below shown on the creation of /home/smb_share directory with the 755 permission for all Samba users:
[root@localhost ~]# mkdir -m 4755 /home/smb_share
2.  Verify the creating of Samba share directory
[root@localhost ~]# ls -al /home/
total 44
drwxr-xr-x 9 root root 4096 Apr 3 04:40 .
drwxr-xr-x 25 root root 4096 Apr 3 03:42 ..
drwsr-xr-x 2 root root 4096 Apr 3 04:40 smb_share
[root@localhost ~]#

Enable Samba share directory.

1. To add share directory / folder for Samba, You can click either the Add Share button or go to and click File -> Add Share from the menu on the Samba Configuration window
open add share button         open add share from File menu
Figure: smb/add_share.png and smb/add_share2.png
2. On the Create Samba share window, on the Basic tab, you can configure the samba share directory, share name and directory description.  Remember that we already create the directory named smb_share, now click Browse button and point to the directory that we create earlier, then point and click the Access tab to proceed.
Example of the Samba share Basic configuration:
Basic tab on Create Samba Share windows
Figure: smb/samba_share_basic.png
3.  On the Access tab, you can specify the user that can be allow to access the share directory, you can select the user from the list or you can click the radio button to Allow accecc to everyone.
samba allow access to specific user
Figure: smb/samba_share_access.png
4.  The example of samba share directory.
samba server share directory
Figure: smb/samba_server_share.png

Restart / Reload Samba server Configuration.

After finish with all the configuration of samba sever it better that you restart the Samba Server to reload the samba config file.  The command example below show the step by step to restart the Samba Server.
[root@localhost samba]# /etc/rc.d/init.d/smb
Usage: /etc/rc.d/init.d/smb {start|stop|restart|reload|status|condrestart}
[root@localhost samba]# /etc/rc.d/init.d/smb status
smbd (pid 3023 1941 1933) is running...
nmbd (pid 1936) is running...
[root@localhost samba]# /etc/rc.d/init.d/smb stop
Shutting down SMB services: [ OK ]
Shutting down NMB services: [ OK ]
[root@localhost samba]# /etc/rc.d/init.d/smb start
Starting SMB services: [ OK ]
Starting NMB services: [ OK ]
[root@localhost samba]# /etc/rc.d/init.d/smb reload
Reloading smb.conf file: [ OK ]
[root@localhost samba]#
Using 'service' command to start, stop or reload the samba server configuration file:
[root@localhost samba]# service
Usage: service < option > | --status-all | [ service_name [ command | --full-restart ] ]
[root@localhost samba]# service smb status
smbd (pid 3522 3517) is running...
nmbd (pid 3520) is running...
[root@localhost samba]# service smb stop
Shutting down SMB services: [ OK ]
Shutting down NMB services: [ OK ]
[root@localhost samba]# service smb start
Starting SMB services: [ OK ]
Starting NMB services: [ OK ]
[root@localhost samba]# service smb reload
Reloading smb.conf file: [ OK ]
[root@localhost samba]#

Automatically start Samba server on start up.

Automatically start samba service after boot on runlevel 3 and on the runlevel 5 ...
1.  Use the 'chkconfig' command to list the samba (smb) service automatically start on all runlevel.
[root@localhost ~]# chkconfig --list smb
smb 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@localhost ~]#
2.   The 'chkconfig' command below enable the samba server to automatically start when boot up, on runlevel 3 and runlevel 5.
[root@localhost ~]# chkconfig --level 35 smb on
[root@localhost ~]#
3.  Check to verify the configuration change.
[root@localhost ~]# chkconfig --list smb
smb 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@localhost ~]#
Samba related article:
1.  The example of smb.conf, the samba sever configuration file, smbpasswd and smbuser file located in /etc/samba/ directory.
2.  Access Samba share from Windows computer.
3.  Mount Windows share from Fedora Core Linux.
Keywords: samba server, configure samba, Linux samba server, setup samba on fedora, configure samba, samba file sever, system-config-samba, share printer, share file linux sharing, sharing file on linux, smbpasswd, smbusers, smb.conf, fedora share file.

No comments:

Post a Comment