Samba Installation and Basic Setup
This guide will walk you through the steps of setting up a basic home or small office file and print server to use with Windows clients or unix/linux clients/servers.
(Important: Read agreement at bottom of document before continuing)

  1. Open a terminal and switch to root or use sudo to run commands.

    [jesse@localhost ~]$ su -
    Password:

    [root@localhost ~]#


  2. Run ipconfig to get the ip address of the computer that will run Samba(make sure that this computer always uses this ip address). This pc has ip address 192.168.0.119.

    [root@localhost ~]# ifconfig
    eth0 Link encap:Ethernet HWaddr 00:0F:B0:38:CF:1D
    inet addr:192.168.0.119 Bcast:192.168.0.255 Mask:255.255.255.0
    inet6 addr: fe80::20f:b0ff:fe38:cf1d/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:3260 errors:0 dropped:0 overruns:0 frame:0
    TX packets:3111 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:2823119 (2.6 MiB) TX bytes:312244 (304.9 KiB)
    Interrupt:18 Base address:0xc800




  3. Open the 'hosts' file.

[root@localhost ~]# nano /etc/hosts


  1. Add the following line to give your computer a hostname. Use the ip address from last step and use a hostname of your choice but remember to use the hostname you elect to use for the examples that require it.

    # Do not remove the following line, or various programs
    # that require network functionality will fail.
    127.0.0.1 localhost.localdomain localhost localhost
    192.168.0.119 lintush

    ::1 localhost6.localdomain6 localhost6



  2. Save the file and exit.

  3. Run the hostname command, restart the network services, and if your hostname doesn't change then try restarting the computer.

    [root@localhost ~]# hostname lintush
    [root@lintush ~]# service network restart

  4. Install Samba (a file server that provides interoperability between Linux/Unix servers and Windows clients).

[root@lintush ~]# yum groupinstall 'Windows File Server'

  1. Now install SWAT (Samba Web Administration Tool) and documentation, very helpful when you need to refer to configuration options.

    [root@lintush ~]# yum install samba-doc samba-swat xinetd


  2. Enable SWAT. Open file 'swat' with the editor of your choice. I used nano.

    [root@lintush ~]# nano /etc/xinetd.d/swat


  3. Find the line below:

disable = yes


  1. Change line to:

disable = no

  1. Save the file and exit editor.

  2. Create a group and user for Samba, such as group “family”, user “John Doe” with password “123456.” Replace “family”, “John doe” and “123456” with values to fit your needs but remember to use this user-names when the examples call for them.

[root@lintush ~]# groupadd family
[root@lintush ~]# useradd -c "John Doe" -m -g family -p 123456 john

Also run the command below to make sure the password for john is set

[root@lintush ~]# passwd john
  1. Add users to the Samba database. Make sure you add root as well.

[root@lintush ]# smbpasswd -a john
New SMB password:
Retype new SMB password:
Added user john.


[root@lintush ]# smbpasswd -a root
New SMB password:
Retype new SMB password:

Added user root.


  1. Add the Samba clients' group that will be used to add machine or computer accounts on the fly or dynamically when login in from a Windows XP client.

    [root@lintush ]# groupadd samba-clients


  2. Create the directories for the shares.

[root@localhost ~]# cd /srv
[root@localhost srv]# mkdir samba
[root@localhost srv]# cd samba
[root@localhost samba]# mkdir profiles
[root@localhost samba]# mkdir netlogon
[root@localhost samba]# mkdir software
[root@localhost samba]# mkdir games
[root@localhost samba]# mkdir pictures
[root@localhost samba]# mkdir movies
[root@localhost samba]# mkdir music
[root@localhost samba]# mkdir shared
  1. Change access rights to 'shared' and 'profiles' directory. Set mode to 1777 this will set sticky bit which is very useful when you have a public or shared resource and you want users to control what they share.

    [root@lintush samba]# chmod 1777 shared
    [root@lintush samba]# chmod 1777 profiles

  2. Create logon script for the 'family' group. This script will map users, belonging to the family group, to all resources(Software, Games, etc.) or shares defined in the smb.conf file.

[root@lintush samba]# gedit netlogon/family.bat.linux


Copy the text below into the file: (fedora7 is going to be our netbios name for the file server)

echo off
echo Setting Current Time...
echo.
net time \\fedora7 /set /yes
echo.
echo Mapping Network Drives to Samba Server...
echo.
net use s: \\fedora7\Software
net use r: \\fedora7\Games
net use p: \\fedora7\Pictures
net use m: \\fedora7\Movies
net use q: \\fedora7\Music

net use t: \\fedora7\Shared



Save the file and exit.

  1. Convert the script to a dos file.

    [root@lintush samba]# unix2dos < netlogon/family.bat.linux > netlogon/family.bat


  2. Change script access rights to 755

[root@lintush samba]# chmod 755 netlogon/family.bat

  1. Configure samba. Open file '/etc/samba/smb.conf.'

    [root@lintush samba]# mv /etc/samba/smb.conf /etc/samba/smb.conf.original
    [root@lintush samba]# nano /etc/samba/smb.conf

  2. Paste the configuration below: (You can replace 'Linux' and 'Fedora7' to your liking but remember to use those values when the examples call for them. Server string you can change it to whatever you like, but keep it short as it is part of the drive description that shows up under Windows. A long name can be annoying. Also, adjust the highlighted text to match your network.)

    [global]
            workgroup = linux
            netbios name = fedora7
            server string = Server
            passdb backend = tdbsam
            passwd program = /usr/bin/passwd %u
            passwd chat = *New*password* %n\n *Retype*new*password* %n\n *passwd:*all*authentication*tokens*updated*successfully*
            unix password sync = Yes
            log level = 3
            log file = /var/lib/samba/log/%U.log
            max log size = 100
            time server = Yes
            printcap name = /etc/printcap
            add user script = /usr/sbin/useradd -m %u
            delete user script = /usr/sbin/userdel -r %u
            add group script = /usr/sbin/groupadd %g
            delete group script = /usr/sbin/groupdel %g
            add user to group script = /usr/sbin/groupmod -A %u %g
            delete user from group script = /usr/sbin/groupmod -R %u %g
            add machine script = /usr/sbin/useradd -c 'Samba PC' -d /var/lib/nobody -g samba-clients -s /bin/false %m$
            logon script = %G.bat
            logon path = \\%L\Profiles\%U
            logon drive = H:
            logon home = \\%L\%U\.profile
            domain logons = Yes
            os level = 65
            preferred master = Yes
            domain master = Yes
            admin users = root
            hosts allow = 127.0.0.1, 192.168.0.0/24
            hosts deny = 0.0.0.0/0
            profile acls = Yes
            sync always = Yes
    
    
    [Profiles]
            comment = User Profile Storage
            path = /srv/samba/profiles
            valid users = root, @family
            write list = root,@family
            read only = No
            create mask = 0700
            directory mask = 0700
            browseable = No
    
    [homes]
            comment = Home Directories
            valid users = %S
            read only = No
            create mask = 0700
            directory mask = 0700
            browseable = No
    
    [netlogon]
            comment = Network Logon Services
            path = /srv/samba/netlogon
            valid users = root, @family
            write list = root
            browseable = No
    
    [printers]
            comment = All Printers
            path = /var/spool/samba
            valid users = root, @family
            create mask = 0666
            guest ok = Yes
            printable = Yes
            browseable = No
    
    [Software]
            comment = Programs & drivers storage area
            path = /srv/samba/software
            valid users = root, @family
            write list = root
            read only = No
            create mask = 0775
            directory mask = 0775
    
    [Games]
            comment = Games storage area
            path = /srv/samba/games
            valid users = root, @family
            write list = root
            read only = No
            create mask = 0775
            directory mask = 0775
    
    [Pictures]
            comment = Photo storage area
            path = /srv/samba/pictures
            valid users = root, @family
            read list = @family
            write list = root
            read only = No
            create mask = 0775
            directory mask = 0775
    
    [Movies]
            comment = Movie storage area
            path = /srv/samba/movies
            valid users = root, @family
            read list = @family
            write list = root
            read only = No
            create mask = 0775
            directory mask = 0775
    
    [Music]
            comment = Music storage area
            path = /srv/samba/music
            valid users = root, @family
            write list = root
            read only = No
            create mask = 0775
            directory mask = 0775
    
    [Shared]
            comment = Shared area for family
            path = /srv/samba/shared
            valid users = root, @family
            write list = root, @family
            read only = No
            create mask = 0755





  3. Save the file and exit.

  1. Before we start Samba, lets run a quick check on the configuration to make sure its correct and valid. Your output should be similar to the output below. If no errors were reported than you are good to go.

[root@localhost samba]# testparm /etc/samba/smb.conf
Load smb config files from /etc/samba/smb.conf
Processing section "[Profiles]"
Processing section "[homes]"
Processing section "[netlogon]"
Processing section "[printers]"
Processing section "[Software]"
Processing section "[Games]"
Processing section "[Pictures]"
Processing section "[Movies]"
Processing section "[Music]"
Processing section "[Shared]"
Loaded services file OK.
Server role: ROLE_DOMAIN_PDC
Press enter to see a dump of your service definitions


[global]
workgroup = LINUX
netbios name = FEDORA7
server string = Server
passdb backend = tdbsam
passwd program = /usr/bin/passwd %u
passwd chat = *New*password* %n\n *Retype*new*password* %n\n *passwd:*all*authentication*tokens*updated*successfully*
unix password sync = Yes
log level = 3
log file = /var/lib/samba/log/%U.log
max log size = 100
time server = Yes
printcap name = /etc/printcap
add user script = /usr/sbin/useradd -m %u
delete user script = /usr/sbin/userdel -r %u
add group script = /usr/sbin/groupadd %g
delete group script = /usr/sbin/groupdel %g
add user to group script = /usr/sbin/groupmod -A %u %g
delete user from group script = /usr/sbin/groupmod -R %u %g
add machine script = /usr/sbin/useradd -c 'Samba PC' -d /var/lib/nobody -g samba-clients -s /bin/false %m$
logon script = %G.bat
logon path = \\%L\Profiles\%U
logon drive = H:
logon home = \\%L\%U\.profile
domain logons = Yes
os level = 65
preferred master = Yes
domain master = Yes
admin users = root
hosts allow = 127.0.0.1, 192.168.0.0/24
hosts deny = 0.0.0.0/0
profile acls = Yes
sync always = Yes


[Profiles]
comment = User Profile Storage
path = /srv/samba/profiles
valid users = root, @family
write list = root, @family
read only = No
create mask = 0700
directory mask = 0700
browseable = No


[homes]
comment = Home Directories
valid users = %S
read only = No
create mask = 0700
directory mask = 0700
browseable = No


[netlogon]
comment = Network Logon Services
path = /srv/samba/netlogon
valid users = root, @family
write list = root
browseable = No


[printers]
comment = All Printers
path = /var/spool/samba
valid users = root, @family
create mask = 0666
guest ok = Yes
printable = Yes
browseable = No


[Software]
comment = Programs & drivers storage area
path = /srv/samba/software
valid users = root, @family
write list = root
read only = No
create mask = 0775
directory mask = 0775


[Games]
comment = Games storage area
path = /srv/samba/games
valid users = root, @family
write list = root
read only = No
create mask = 0775
directory mask = 0775


[Pictures]
comment = Photo storage area
path = /srv/samba/pictures
valid users = root, @family
read list = @family
write list = root
read only = No
create mask = 0775
directory mask = 0775


[Movies]
comment = Movie storage area
path = /srv/samba/movies
valid users = root, @family
read list = @family
write list = root
read only = No
create mask = 0775
directory mask = 0775


[Music]
comment = Music storage area
path = /srv/samba/music
valid users = root, @family
write list = root
read only = No
create mask = 0775
directory mask = 0775


[Shared]
comment = Shared area for family
path = /srv/samba/shared
valid users = root, @family
write list = root, @family
read only = No

create mask = 0755

  1. Configure Samba's 'smbd' daemon to start automatically.

    [root@localhost samba]# chkconfig --level 235 smb on



  2. Start the smbd daemon(server that provides SMB/CIFS services to clients). There are two methods of starting the Samba daemon. Method one utilizes the terminal and the other method uses the SWAT tool to start and stop Samba daemons and to change configuration options. Method two will be covered later in the guide.

    Method 1 (Method 2 will be covered later)

    [root@localhost samba]# service smb start


    OR

[root@localhost samba]# /etc/init.d/smb start

  1. Since Samba is now running, lets validate connectivity to the loop-back interface by sending a null user-name and password (-u%). Samba should answer back with something similar to the output below. Indicating that it is responding to the loop-back interface.

    [root@localhost samba]# smbclient -L localhost -U%
    Domain=[LINUX] OS=[Unix] Server=[Samba 3.0.28-0.fc8]


    Sharename Type Comment
    --------- ---- -------
    Software Disk Programs & drivers storage area
    Games Disk Games storage area
    Pictures Disk Photo storage area
    Movies Disk Movie storage area
    Music Disk Music storage area
    Shared Disk Shared area for family
    IPC$ IPC IPC Service (Server)
    PSC_2350_series Printer HP PSC 2350 series
    Domain=[LINUX] OS=[Unix] Server=[Samba 3.0.28-0.fc8]


    Server Comment
    --------- -------
    FEDORA7 Server


    Workgroup Master
    --------- -------

    LINUX FEDORA7



  2. Next is checking that Samba correctly handles valid users and that it answers to its server name(in this case is 'lintush') correctly. The output should be identical to the previous one.

    [root@localhost samba]# smbclient -L lintush -Ujohn%123456
    Domain=[LINUX] OS=[Unix] Server=[Samba 3.0.28-0.fc8]


    Sharename Type Comment
    --------- ---- -------
    Software Disk Programs & drivers storage area
    Games Disk Games storage area
    Pictures Disk Photo storage area
    Movies Disk Movie storage area
    Music Disk Music storage area
    Shared Disk Shared area for family
    IPC$ IPC IPC Service (Server)
    PSC_2350_series Printer HP PSC 2350 series
    john Disk Home Directories
    Domain=[LINUX] OS=[Unix] Server=[Samba 3.0.28-0.fc8]


    Server Comment
    --------- -------
    FEDORA7 Server


    Workgroup Master
    --------- -------

    LINUX FEDORA7


  3. Test connectivity with one of Samba's shared resources (in this case , the 'Shared' resource) with an actual user. If you get similar output as the following then you successfully logged in.

    [root@localhost samba]# smbclient //lintush/Shared -Ujohn%123456
    Domain=[LINUX] OS=[Unix] Server=[Samba 3.0.28-0.fc8]

    smb: \>


  4. Exit Samba's 'Shared' resource.


    smb: \> exit


  5. Configure nmbd daemon to start automatically.

    [root@lintush ~]# chkconfig --level 235 nmb on


  6. Start the nmbd daemon (NetBIOS name server that provides NetBIOS over IP naming services to clients).

    [root@localhost samba]# service nmb start


    OR

    [root@localhost samba]# /etc/init.d/nmb start


  7. Now check on the Network to see if the NetBIOS name shows up. Click on Places-Network and you should see FEDORA7 as illustrated in the image below:





  8. To see the workgroup 'linux', double-click on Windows Network. You should see something similar to the image below showing the 'linux' workgroup. This image also shows my samba server 'fc7' which is my file server. If you just get a blank window then you have to wait about 15 minutes and then you will see the work-group.





  9. Double-click on 'linux' and then double-click on 'FEDORA7' and you should see the shares available.





  10. Now double-click on the 'Shared' resource or folder to login to it and provide a valid user-name and password. You will get a window similar to the following:

    Use the following credentials:

    Username: john
    Domain: LINUX
    Password: 123456




    You should now be able to create folders in there or save stuff to that folder.


Using SWAT for Administration of Samba
(this is method 2 of starting and stopping Samba daemons or services)


  1. Since SWAT was configured earlier, lets configure the super-server xinetd to start automatically.

    [root@lintush samba]# chkconfig --level 235 xinetd on


  2. Lets start the super-server xinetd so that SWAT can start.

    [root@lintush samba]# service xinetd start


  3. Lets check to see if we can log in to it. Open up a browser and enter http://localhost:901 and you should get a log in window. Use root and the root password to log in.




  4. After you log in, click on status and you can stop or start services from here.




    Explore the menus. You can also make changes to the configuration file form here and restart the services so that new changes can take effect.



Windows XP Configuration

  1. Lets add a Windows XP client to the domain. Go to a Windows XP pc that you want to use with Samba and log in as the administrator or a user with administrative privileges. After you log in, right-click on My Computer and click on Properties.




  2. On the properties windows, click on Computer name to get the options below.




  3. While in the Computer Name options, click on Change to get the following options.




    Click on radio button for Domain and enter the following information in the Domain text box:

    linux

  4. Click on OK and you will be prompted to enter a username and password. Use the root and root password for your system.




  5. Now click on OK and a few seconds later a window pops up to welcome you to the linux domain.




  6. Now restart the computer.

  7. After it boots, you will have to press Ctlr-Alt-Del to get the log in window. Use the following user information to log in:

    User name: john
    Password: 123456
    Log on to: linux

    NOTE: When selecting a server/domain from the Log on to: drop down box, Windows may seem to be hung up but its not. Just press Ctrl-Alt-Del and it will allow you to choose the server from the list. Select or click on linux.



  1. Once you successfully log in with user john, open up my computer and you will see the Samba shares mapped to drive letters. Thats it. Done.










Agreement

This guide is provided as is with no warranty, garantee, or liability of any kind. Use it at your own risk. I am not responsible for any damages arising from the use of this guide. If you agree to these terms than you will use the guide with the understanding that you will not hold me responsible for any damages, whatever their nature, resulting from the use of this guide.





Comments











Post your Comments






Enter your message:

Your name:

Date: Friday-November-21-2008 02:06:49 am
(Actual time will vary at the time the message is posted.)

You can also leave a picture to go with your message.(optional)
All image types supported.
Picture to upload:

Message: