Tuesday, February 8, 2011

How To install and test SAMBA

Samba is a suite of utilities that allows your Linux box to share files and other resources, such as printers, with Windows boxes. Samba Domains and Linux share the same usernames so you can log into the Samba based Windows domain using your Linux password and immediately gain access to files in your Linux user's home directory. For added security you can make your Samba and Linux passwords different.
When it starts up, and with every client request, the Samba daemon reads the configuration file /etc/samba/smb.conf to determine its various modes of operation. 

The Samba Configuration File

The /etc/samba/smb.conf file is the main configuration file you'll need to edit. It is split into five major sections,

  File Format - smb.conf

Section Description
[global] General Samba configuration parameters
[printers] Used for configuring printersUsed for configuring printers
[homes] Defines treatment of user logins
[netlogon] A share for storing logon scripts. (Not created by default.)
[profile] A share for storing domain logon information such as "favorites" and desktop icons. (Not created by default.)

Samba Passwords

You should be aware that your Linux password and Samba passwords are stored in two different locations. This provides the Samba administer the flexibility of allowing only some of the Linux users to have Samba accounts.
Use the passwd command to change Linux passwords, which are stored in the /etc/shadow file. Samba passwords are stored in the /etc/samba/smbpasswd file and can be changed smbpasswd command.

How To Add Users To Your Samba Domain

 Adding users to a domain has three broad phases. The first is adding a Linux user on the Samba server, the second is creating a Samba smbpasswd that maps to the new Linux user created previously, and the third is to map a Windows drive letter to the user's Linux home directory. Let's take a closer look:

Adding The Users In Linux

First, go through the process of adding users in Linux just as you would normally. Passwords won't be necessary unless you want the users to log in to the Samba server via telnet or ssh.

Create the user

To create the user, use the command:
useradd -g 100 pankaj

Give them a Linux Password

Giving them a Linux password is only necessary if the user needs to log into the Samba server directly. If the user does, use this method:
passwd pankaj
Changing password for user pankaj.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.Mapping The Linux Users To An smbpassword

Next, you need to create Samba domain login passwords for the user
/usr/bin/smbpasswd -a username password
The -a switch adds the user to the /etc/smbpasswd file. Use a generic password then have users change it immediately from their workstations in the usual way.
Remember the smbpasswd sets the Windows Domain login password for a user, which is different from the Linux login password to log into the Samba box.

Mapping A Private Windows Drive Share

By default, Samba automatically gives each user logged into the domain an H: drive that maps to the /home/username directory on the Linux box.

Mapping Using "My Computer"

If the auto-mapping doesn't work then try:
  1. Let the user log into the domain.
  2. Right-click on the "My Computer" icon on the desktop.
  3. Click on "Map Network Drive".
  4. Select a drive letter.
  5. Browse to the HOMENET domain, then the Samba server, then the user's home directory.
  6. Click on the check box "Reconnect at Logon", to make the change permanent

Mapping from the Command Line

If you find the "My Computer" method too time consuming for dozens of users or if the PC doesn't have the feature available, then you can use the command-line method and possibly make it into a script.
1. Create a master logon batch file for all users
vi /home/samba/netlogon/login.bat
2. Add the following lines to mount the user's share as drive P: (for private).
REM Drive Mapping Script
net use P: \\server-name\
3. Make the file world readable using:
chmod 644 /home/samba/netlogon/login.bat
4. Linux and Windows format text files slightly differ. As the file resides on a Linux box, but will be interpreted by a Windows machine, you'll have to convert the file to the Windows format. Use the unix2dos command.
unix2dos /home/samba/netlogon/login.bat
unix2dos: converting file /home/samba/netlogon/login.bat
to DOS format ...
[root@bigboy tmp]#
5. The final step is to edit your smb.conf file's [global] section have a valid entry for the logon script parameter. This can be done using SWAT via the Globals menu.
  logon script = login.bat
Now your users will have additional disk space available on a Windows P: drive whenever they login.

Note that this document comes without warranty of any kind. But every effort has been made to provide the information as accurate as possible. I welcome emails from any readers with comments, suggestions, and corrections at webmaster_at admin@linuxhowto.in

Copyright © 2012 LINUXHOWTO.IN


  1. For sharing printers and shared directory, what should be the entry in smb.conf file. Please give one example....

  2. I am having problem in configuring Samba server version 3.0.
    I am trying to configure samba server on rhel 6 with windows 7. But are unsuccessful till now.
    I am getting error.
    Network path was not found .
    Error 0x080070035.
    I have changed the Lan Manager required Authentication. Then also it didn't worked.
    Please help me out.
    Thank you.

    1. Is iptables running in the samba machine ?
      from the XP box try
      telnet 139
      port 139 is samba port and if telnet is successful and you get a blank screen, then there is no problem with iptables. If telnet hangs, then you have to look into eihter adding 139 as trusted port or to stop iptables if the machine is in secure network.