Samba is an application that allows a Linux or UNIX host to act as a file server for Windows systems and Windows systems can access UNIX filesystems and printers using their native Windows networking. We'll demonstrate a Linux system mounting a Windows drive and a Windows system mapping a Linux drive in this section.
Samba provides its file-sharing functionality using Server Message Block (SMB) protocol. SMB runs on top of TCP/IP. In our example in this section, both the Windows system and UNIX system are running TCP/IP and SMB. These provide all of the technology that is required to establish file sharing between the two systems.
At the time of this writing Samba contains the functionality just mentioned: file-sharing, printer sharing, and advanced user access control of files. There are many advancements taking place with Samba and other software provided under GNU Public License (GPL) as free software. Because the software is free, many people have access to it and spend time enhancing the software. For this reason, you may find that additional functionality is included in Samba and other such software.
Because Samba is supplied on the Red Hat Linux CD-ROM, we'll walk through a simple Samba setup using Red Hat Linux. When installing Red Hat Linux, you can select the software packages you wish to load, as you can on most all UNIX variants. If you did not load Samba at the time you originally loaded the operating system, you can use a graphical RPM tool or rpm from the command line to load Samba or any other software.
The configuration file for Samba is /etc/samba/smb.conf. The smb.conf file has all Samba-related setup information in it. For our simple Samba setup in this chapter we need to have only a few lines in the file setup. We need to have a few Global Settings and Share Definitions in order to achieve our file system sharing between the Windows and Linux systems. The following are three select sections from smb.conf that were modified for our example in this section:
# workgroup = NT-Domain-Name or Workgroup-Name
workgroup = DEVENV
encrypt passwords = yes
smb passwd file = /etc/samba/smbpasswd
comment = Home Directories
browseable = yes
writable = yes
valid users = %S
create mode = 0664
directory mode = 0775
We have a workgroup of DEVENV specified.
We want our passwords to be encrypted and we'll use the file /etc/samba/smbpasswd for these encrypted passwords. We'll have a user on both the Windows and Linux systems with the same name.
We have some information related to our Share Definitions, such as making the Home Directories browseable.
We made only these three modifications to the smb.conf file; however, next we'll run a Samba utility called testparm. This utility will check our /etc/smb.conf file for errors. This utility produces a very long output which I won't include here, but you'll want to run this and check for any warnings or errors it produces.
# testparm smb.conf
Load smb config files from smb.conf
Processing section "[homes]"
Processing section "[printers]"
Loaded services file OK.
Press enter to see a dump of your service definitions
# Global parameters
coding system =
client code page = 850
code page directory = /usr/share/samba/codepages
workgroup = DEVENV
netbios name =
netbios aliases =
netbios scope =
server string = Samba Server
bind interfaces only = No
security = USER
encrypt passwords = Yes
update encrypted = No
allow trusted domains = Yes
hosts equiv =
min passwd length = 5
map to guest = Never
null passwords = No
obey pam restrictions = Yes
password server =
smb passwd file = /etc/samba/smbpasswd
There were not warnings or errors produced from having run testparm so we'll proceed to the next step
We now need to create a user on both the Linux and Windows systems that can be used for our Samba-related work. It may already be that you have suitable users on your system. For the purposes of this demonstration we'll create a user on both systems.
On the Linux system we can use the useradd program from the command line or User Manager graphical program (Programs-System-User Manager) to add the user. The user will appear in the /etc/passwd file after they have been added. We'll then issue the following command to add the encrypted user passwd to the /etc/samba/smbpasswd file:
# smbpasswd -a linuxconnect
linuxconnect is the name of the user we created for this example. You can view the smbpasswd file to see the entry for your user.
This same user was created on the Windows system.
You can start Samba daemons every time the system boots or start them at the command line. The following commands show starting the daemons at the command line and then viewing them:
# /sbin/service smb start
Starting SMB services: [ OK ]
Starting NMB services: [ OK ]
# ps -ef | grep mbd
root 10828 1 0 16:59 ? 00:00:00 smbd -D
root 10833 1 0 16:59 ? 00:00:00 nmbd -D
We started the daemons with /sbin/service smb start and check to see our two daemons running with ps. Should you make a change to your Samba setup and wish to restart the daemons, you could use /sbin/service smb restart.
The smbd server daemon provides the file and print services to SMB clients, such as Windows systems. SMB stands for "Server Message Block" and is defined as a network protocol for sharing files, printers, serial ports, and communications abstractions such as named pipes and mail slots between computers.
The nmbd server daemon allows for NetBIOS over IP name service requests over a network, like those produced by SMB/CIFS clients such as Windows systems. We have now performed all of the basic setup required to proceed with mounting disks
Mapping a Windows Drive to a Linux Directory
Now we can both browse the Linux system from Windows as well as mount a specific drive directory of the Linux system on our Windows system. Now we specify the Linux system and directory we will mount as F: on the Windows system:
We specified the path of \\linuxdev\linuxconnect to mount on the Windows system drive F:. This is the hostname (linuxdev) and the username (linuxconnect). The system knows automatically to go to the home directory for linuxconnect and mounts that directory as F: for us on the Windows system
Let's now get the overall status of the Samba setup with the smbclient utility on our Linux system, as shown in the following listing:
# su - linuxconnect
$ smbclient -L linuxdev
added interface ip=192.168.1.102 bcast=192.168.1.255 nmask=255.255.255.0
Domain=[DEVENV] OS=[Unix] Server=[Samba 2.2.3a]
Sharename Type Comment
--------- ---- -------
homes Disk Home Directories
IPC$ IPC IPC Service (Samba Server)
ADMIN$ Disk IPC Service (Samba Server)
linuxconnect Disk Home Directories
LINUXDEV Samba Server
Before issuing the smbclient command we changed user to linuxconnect and then issued the command.
This utility produces a useful summary of the Samba setup, including the share linuxconnect we set up, the Samba server for our example, and other useful information