CSS Corp Open Source Services

Samba – A short guide for sharing files and printers

with 2 comments

Introduction

Samba is a service in Unix like operating systems which can be used to share folders across a Windows Network. Samba is a standard service among almost all the Linux distributions.Samba can perform the following operations.

  1. Act as file server among Windows and Linux machines
  2. Act as a printer sharing service
  3. Act as a domain controller for a Windows network
  4. Act as a client under a Windows domain

Samba Diagram

Details

Samba Port No 445
Folders related to Samba /etc/samba/usr/lib/samba/usr/share/doc/samba-x.x.x/usr/log/samba
Samba Configuration file /etc/samba/smb.conf
Starting, stopping and restarting Samba server /etc/init.d/smb {start | stop | restart} (Red hat, Debian,SUSE)
/etc/init.d/samba {start | stop | restart} (Ubuntu)
File-system CIFS

Driver file /sbin/mount.cifs
Kernel Module cifs.ko
GUI Configuration tool System-config-samba ( Red hat, Ubuntu)
Web Configuration tool SWAT

SWAT Port No 901
Service Part of xinetd or inetd
Swat documents folder /usr/share/swat

Installation

Samba can be installed using the following commands.

For installing Samba on a Ubuntu or Debian  machine, use the following command:

$ sudo apt-get install samba

For installing Samba on a Fedora or any other Redhat based machine, use the following command:

$ yum install samba

If you want to install Samba from a source package, you can download it from the following link:

http://samba.org/samba/download/

Installing system-config-samba

system-config-samba is a GUI tool which is used to configure Samba server in a Linux machine with GUI. You can install it by using the appropriate commands below.

 $ yum install system-config-samba (for Redhat based) 
 $ sudo apt-get install system-config-samba (for Debian based) 

SWAT

SWAT is web based configuration tool which helps to configure the Samba server from a remote location. It is often used to configure complex smb.conf files. SWAT uses port no 901 to access the Samba server.

Installation

SWAT can be installed on a Redhat based OS using the following command:

 $ yum install samba-swat 

For a Debian based system the command would be as follows:

 $ sudo apt-get install swat 

Configuration of Samba using SWAT

Open a browser in a remote or local machine and enter the following address in the address bar

http://<ip-address of the samba server>:901

Now you can browse through the page to configure various options such as adding shares and adding printers.

User Management in Samba

Using command line

For authentication, Samba uses a separate set of users that differ from the Linux users. Hence we need to create Samba users for accessing the shares form a Samba server.

To create  a Samba user the following command can be used:

 $ smbpasswd -a  <username>

To delete a Samba user you can use the following command

 $ smbpasswd -x  <username>

Adding Samba users using system-config-samba

Use the following steps to add users

  • Goto Gnome menu-> System -> Administration-> Samba.
  • A window opens, click preferences-> Samba users.
  • Another Window opens, click add user.
  • Another window opens, Choose the Relevant Linux username from “UNIX username” Dropdown menu, Enter the Samba username as it would be used in a client machine.
  • Enter the password and enter it again to confirm.
  • Click “OK”.
  • You can find the screenshots below

    Sharing Folders

    Sharing folders using command line

    The configuration file for Samba is /etc/samba/smb.conf.

    For sharing a folder in Samba you can append the following lines to the file.

    [<share-name>]
    path =<share-path>
    Browseable = yes
    Guest ok = yes
    read only = no
    Valid users = <user1>,<user2> 

    Restart the Samba service by using the following command:

    $ sudo /etc/init.d/samba restart

    Sharing folders using system-config-samba

    The sharing can also be done using the GUI toot. You can share the folders using the following procedure:

  • Goto Gnome menu-> System-> Administration-> Samba
  • A window opens, Click on “Add  Share”
  • Another Window opens, In the “Basic” Tab enter the directory path, share name and Description about the share.
  • Choose whether the Share should be writable using the check box
  • You can also choose whether the share should be visible while browsing.
  • At the tab named “access” , click on “Only allow access to specific users” and check the user’s name for whom the access needs to be provided.
  • Otherwise click on “Allow access to everyone” to allow access to everyone.
  • You can find the screenshots below.

    Accessing the Samba share from a Windows Client

    Accessing the Samba share directly

  • Goto Start menu -> Run
  • Enter the ip-address of the Samba server.
  • Now a Windows explorer will open showing the shared folders from the Samba server
  • Now goto the folder showing with which it has been shared in the server
  • If you want to browse through the network

    Goto Start Menu -> Computer, A window will open, Click on Network. It shows all the network computers, including your Samba server, connected to your PC. Now you can browse through the network.

    To mount the share every time Windows boots, use the following steps:

  • Click on Start Menu.
  • Right click on My Computer and click Map Network Drive.
  • A Window will open, Choose a Drive letter and mention the path in “Folder” in /<ip-address>/ format.
  • Check the box “Reconnect at logon”.
  • If you want to enter the login credentials of the Samba server click on “Connect using a different User name” and enter the user-name and password.
  • Click Finish.
  • Accessing the Samba share from a Linux machine with Gnome

    Accessing the Samba share directly

  • Goto Gnome menu-> Places -> Connect to server.
  • A window will open. Choose “Service type” as Windows share.
  • Enter the server’s Ip-address at the “Server” tab.
  • Share name of the folder at the “Share” tab.
  • Enter the Username.
  • Enter the domain name.
  • Click “Connect”.
  • Enter the password and click “Connect”.
  • You can view the screenshots below

    If you want to browse through the network

  • Goto Gnome menu-> Places -> Network
  • A windows will open up showing “Windows Network”
  • Double click on “Windows Network” to browse through the windows network which contains Samba servers also
  • Click on the Samba server by identifying using the hostname in the list
  • To mount the share using Command line interface

    Use the following command:

    $ sudo mount -t cifs /<ip-address>/<share-name>/  /<mount-point> -o user=<username> 

    To mount the share at every boot

    Add the following line to the /etc/fstab file

    //<ip-address>/<share-name>   /<mount-point>   cifs   user=<username>,password=<password>   0 0

    Sharing printers

    Sharing through command line

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

    Restart the Samba service by using the following command:

    $ sudo /etc/init.d/samba restart

    Configuring the shared printer on a Windows Client:

  • Goto Start menu-> Printers and faxes -> Add a printer.
  • A window will open, click next.
  • Select “A network printer, or a printer attached to another computer” and click next.
  • Select “Connect to this printer (or to browse for a printer, select this option and click next)”
  • Enter \\< ip-address >\<printer name as in Linux machine> and click next.
  • It will connect to the printer and may say that the driver is not installed (if driver is present in Windows xp it will proceed without driver installation).
  • Install the drivers.
  • It will prompt “Do you want to this printer as the default printer?”. Select your choice an click next.
  • Click finish.
  • Configuring the shared printer on a Linux Client with Gnome:

  • Go to Gnome menu-> System-> Administration-> Printing.
  • A window will open, Click new.
  • Another Window will open. At devices, drop down Network printer, Click “Windows Printer via Samba”.
  • At the right hand side, There will be a box with ‘smb://’. Here enter the ip-address and the printer name as  “smb:///”
  • Choose the driver and finish the installation.
  • Logging in Samba

    Logs related to Samba can be found in the folder /var/log/samba. When we try to access the Samba share from another machine it creates a new file with the file name in the following format.

    /var/log/samba/log.<hostname>

    Associated services

    nmbd

    nmbd is a NetBIOS name server which is used to resolve NetBIOS names to IP addresses. It is a part of the Samba Suite and in many of the distros, nmbd daemon is automatically started when samba daemon is started.

    nmbd can be started manually using the command:

     $ service nmb start ( For Redhat based machines) 
     $ /etc/init.d/nmbd start (For Ubuntu machines) 

    Some useful commands related to Samba

    findsmb

    findsmd can be used to find the machines in the network which respond to smb queries.

    testparm

    testparm command can be used to test the Samba configuration in the server.

    smbtree

    This command can be used to list all the Samba and Windows file servers in the network.

    2 Responses

    Subscribe to comments with RSS.

    1. very nice tutorial, i was just hang on how to configure samba for both Linux and windows environments and this post help very much. thanks.

      imran

      May 1, 2011 at 6:01 pm


    Leave a comment