Setting Up a Windows Server Using Samba


Setting Up a Windows Server Using Samba

If you rely on Windows for file sharing and print sharing, you probably use Windows in your servers and clients. You can move to a Linux PC as your server without losing the Windows file and printer sharing because a Linux PC can be set up as a Windows server. When you install Red Hat Linux from this book's companion CD-ROMs, you also get a chance to install the Samba software package, which performs that setup. All you have to do is select the Windows File Server package group during installation.

Note 

After you install and configure Samba on your Linux PC, client PCs (running Windows for Workgroups or Windows 95/98/NT/2000/XP) can access disks and printers on the Linux PC by using the Server Message Block (SMB) protocol, the underlying protocol in Windows file and print sharing.

With the Samba package installed, you can make your Linux PC a Windows client, which means that the Linux PC can access disks and printers a Windows server manages.

The Samba software package has these major components:

  • /etc/samba/smb.conf-The Samba configuration file the SMB server uses

  • /etc/samba/smbusers-A Samba configuration file that shows the Samba user names corresponding to user names on the local Red Hat Linux PC

  • nmbd-The NetBIOS name server, which clients use to look up servers (NetBIOS stands for Network Basic Input/Output System-an interface that applications use to communicate with network transports, such as TCP/IP)

  • nmblookup-A command that returns the IP address of a Windows PC identified by its NetBIOS name

  • smbadduser-A program that adds users to the SMB password file

  • smbcacls-A program that manipulates Windows NT access control lists (ACLs) on shared files

  • smbclient-The Windows client, which runs on Linux and allows Linux to access the files and printer on any Windows server

  • smbcontrol-A program that sends messages to the smbd, nmbd, or winbindd processes

  • smbd-The SMB server, which accepts connections from Windows clients and provides file and print sharing services

  • smbmount-A program that mounts a Samba share directory on a Red Hat Linux PC

  • smbpasswd-A program that changes the password for an SMB user

  • smbprint-A script that enables printing on a printer on a SMB server

  • smbstatus-A command that lists the current SMB connections for the local host

  • smbtar-A program that backs up SMB shares directly to tape drives on the Red Hat Linux system

  • smbumount-A program that unmounts a currently mounted Samba share directory

  • testparm-A program that ensures that the Samba configuration file is correct

  • winbindd-A server for resolving names from Windows NT servers

The following subsections describe how to install Samba from the companion CD-ROM and how to set up a printer on the Linux PC to print through Windows.

Checking Whether Samba Is Installed

Check whether Samba is installed, by typing the following command in a terminal window:

rpm -q samba
samba-2.2.7a-2

If the rpm command displays a package name that begins with samba, Samba is already installed on your system, and you should skip this subsection. Otherwise, follow these steps to install Samba from this book's companion CD-ROM:

  1. Log in as root, and make sure that the appropriate companion CD-ROM is in the drive and mounted. If it is not, use the umount /mnt/cdrom command to dismount the current CD-ROM; replace it with the correct CD-ROM, and mount that CD-ROM with the mount /mnt/cdrom command.

  2. Change the directory to the CD-ROM-specifically to the directory where the Red Hat Package Manager (RPM) packages are located-with the following command:

    cd /mnt/cdrom/RedHat/RPMS
  3. Use the following rpm command to install Samba:

    rpm -ivh samba*

    If Samba is already installed, this command returns an error message. Otherwise, the rpm command installs Samba on your system by copying various files to their appropriate locations.

These steps complete the unpacking and installation of the Samba software. Now, all you have to do to use Samba is configure it.

Insider Insight 

Samba comes with documentation on configuring it for SSL support. To read this documentation, change directory with the command cd /usr/share/doc/samba*/ docs/textdocs, and type more Samba-OpenSSL.txt to browse through the text file on OpenSSL-a free implementation of the SSL protocol.

Configuring Samba

To set up the Windows file-sharing and print-sharing services, you have to provide a configuration file named /etc/samba/smb.conf. The configuration file is a text file that looks like a Microsoft Windows 3.1 INI file. You can prepare the file in any text editor on your Red Hat Linux system.

The Samba software comes with a configuration file you can edit to get started. To prepare the configuration file, log in as root, and use your favorite text editor to edit the file /etc/samba/smb.conf. Here's a sample configuration file without any comments:

[global]
    netbios name = LNBP200
    workgroup = LNB SOFTWARE
    server string = LNB Software-Red Hat Linux-Samba Server
    hosts allow = 192.168.0.  127.
    guest account = naba
    log file = /var/log/samba/l%m.log

# Log files can be at most 50KB
    max log size = 50

    security = user
    smb passwd file = /etc/samba/smbpasswd

# Leave the next option as is - it's for performance
    socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192

    remote browse sync = 192.168.0.255
    remote announce = 192.168.0.255/LNB SOFTWARE
    local master = yes
    os level = 33

    name resolve order = lmhosts bcast

    dns proxy = no
    unix password sync = no

[homes]
    comment = Home Directories
    browseable = no
    writable = yes

[printers]
    comment = All Printers
    path = /var/spool/samba
    browseable = no
    guest ok = no
    writable = no
    printable = yes

[tmp]
    comment = Temporary file space
    path = /tmp
    read only = no
    public = yes

[public]
    comment = Public Stuff
    path = /home/samba
    browseable = yes
    public = yes
    guest ok = yes
    writable = yes
    printable = no
    available = yes
    guest only = no
    user = naba
    only user = yes

Change the user name from naba to your user name. Also make sure that all directories mentioned in the configuration file actually exist. For example, create the /home/samba directory with the command mkdir /home/samba.

After editing the Samba configuration file, add two users to the Samba password file. First add your user name. Here's how I add myself:

smbadduser naba:naba
----------------------------------------------------------
ENTER password for naba
New SMB password:          (I enter the password.)
Retype new SMB password:   (I enter password again.)
Password changed for user naba. 
Insider Insight 

After making the changes to the /etc/samba/smb.conf file, type the following command to verify that the file is okay:

testparm

If the command says that it loaded the files okay, you're all set to go.

Start the SMB services with the following command:

service smb start

To start the SMB services automatically when the system reboots, type the following command:

chkconfig --level 35 smb on

Accessing Windows Resources with smbclient

You can use the smbclient program to access shared directories and printers on Windows systems on the LAN and to ensure that your Linux Samba server is working. One quick way to check is to use the smbclient -L command to view the list of services on the Red Hat Linux Samba server itself. This is what I get when I run smbclient on my Linux Samba sever:

smbclient -L LNBP200
added interface ip=192.168.1.200 bcast=192.168.1.255 nmask=255.255.255.0
added interface ip=172.16.128.1 bcast=172.16.128.255 nmask=255.255.255.0
Got a positive name query response from 192.168.1.200 ( 192.168.1.200 )
Password: (I press Enter)
Anonymous login successful
Domain=[LNB SOFTWARE] OS=[Unix] Server=[Samba 2.2.7]
   Sharename     Type      Comment
   ---------     ----      -------
   tmp           Disk      Temporary file space
   public        Disk      Public Stuff
   IPC$          IPC       IPC Service (LNB Software-Red Hat Linux-Samba Server)
   ADMIN$        Disk      IPC Service (LNB Software-Red Hat Linux-Samba Server)

        Server               Comment
        ---------            -------
        LNBP200              LNB Software-Red Hat Linux-Samba Server
        NABA-DELL-4400

        Workgroup            Master
        ---------            -------
        LNB SOFTWARE         NABA-DELL-4400

The output of smbclient shows shared resources and lists the names of the other Windows servers on the local network.

If you have other Windows servers around, you can look at their services with the smbclient program. Here is what I get when I view the shared resources on a Windows 98 PC:

smbclient -L LNBP933
added interface ip=192.168.0.2 bcast=192.168.0.255 nmask=255.255.255.0
Got a positive name query response from 192.168.0.3 ( 192.168.0.3 )
Password: (I press Enter)

        Sharename      Type      Comment
        ---------      ----      -------
        PRINTER$       Disk
        HP NEW        Printer   HP Photosmart on new Dell
        C              Disk      C drive on Dell (2001)
        IPC$           IPC       Remote Inter Process Communication

        Server               Comment
        ---------            -------
        LNBP200              LNB Software-Red Hat Linux-Samba Server
        LNBP400              Dell Dimension XPS-400
        LNBP933              Dell Dimension 4100 (2001)
        NABA-DELL-4400

        Workgroup            Master
        ---------            -------
        LNB SOFTWARE         NABA-DELL-4400

You can do much more than simply look at resources with the smbclient program: you can also use it to access a disk on a Windows server or to send a file to a Windows printer. The smbclient program is like FTP-you connect to a Windows server and use commands to get or put files and to send files to the printer.

The following example shows how I use smbclient to access a disk on my Windows XP PC and view its directory:

smbclient //naba-dell-4400/Share naba mypassword
added interface ip=192.168.0.2 bcast=192.168.0.255 nmask=255.255.255.0
Got a positive name query response from 192.168.0.4 ( 192.168.0.4 )
Domain=[LNB SOFTWARE] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
smb: \> dir
  .                                  DA        0  Sun Jan 12 15:47:36 2003
  ..                                 DA        0  Sun Jan 12 15:47:36 2003
  Ashley                             DA        0  Sat Nov 23 11:32:04 2002
  bookmark.htm                        A   114785  Sun Jun 23 13:48:22 2002
  brother-mfc-10-22-02.rms            A   132633  Tue Oct 22 18:31:36 2002
... lines deleted...
  Photos                              D        0  Mon Jan  6 19:54:54 2003

                38154 blocks of size 2097152. 30719 blocks available
smb: \> quit

To see a list of smbclient commands, type help at the prompt. Table 19-2 is a brief summary of commonly used smbclient commands. To familiarize yourself with smbclient, try as many of these commands as you can.

Table 19-2: Common smbclient Commands

Command

Description

!

Executes a shell command (remember that you run smbclient on Linux)

? cmd

Displays a list of commands or help on a specific command

cancel id

Cancels a print job identified by its ID

cd dir

Changes the remote directory

del file

Deletes the specified file

dir file

Displays the directory listing

exit

Logs off the Windows server

get rfile lfile

Copies a remote file (rfile) to a local file (lfile)

help cmd

Provides help on a command (or displays a list of commands)

lcd newdir

Changes the local directory (on the Linux PC)

lowercase

Toggles automatic lowercase conversion of filenames when executing the get command

ls files

Lists files on the server

mask name

Applies a mask (such as *.c) to all file operations

md dirname

Makes a directory on the server

mget name

Gets all files with matching names (such as *.doc)

mkdir dirname

Makes a directory

mput name

Copies files from the Linux PC to the server

newer file

Gets only the files that are newer than the specified file

print name

Prints the named file

printmode mode

Sets the print mode (the mode must be text or graphics)

prompt

Toggles prompt mode off (similar to the command in ftp)

put lfile rfile

Copies a local file (lfile) to a remote file (rfile)

queue

Displays the print queue

quit

Logs off the Windows server

rd dir

Deletes the specified directory on the server

recurse

Toggles directory recursion during file get and put operations

rm name

Deletes all files with the specified name

rmdir name

Deletes the specified directory

translate

Toggles text translation (converts a line feed to a carriage return-line-feed pair).