Whenever two (or more) computers are connected to each other, there are certain things they want to do: Usually files need to be shared among users on the systems and printers should be available for printing from all workstations (and even from the playstations
). The way to achieve this is called protocol. In order to share files and printers, the OSes on all machines involved have to speak the same language, follow the same protocol.
If only UN*X machines are involved, NFS and LPD are the means of choice. If any Windows-box enters the scene, we will have to use the SMB-Protocol. SMB stands for Server Message Block and was developed for Windows and OS/2. SAMBA is a suite of programs for non-Windows-boxes, which speaks SMB, and thus enables those machines (e.g. our Linux-box) to understand Windows.
To get things moving, we start with the following configuration file, which should be in /etc/samba/. Use ‘locate smb.conf’ if your distribution put it someplace else. The lines starting with a ‘#’ are comments; blanks are ignored.
# /etc/samba/smb.conf
[global]
# put your Windows workgroup after the '='
workgroup = workgroup
# This is default from Win98 on
security = user
encrypt passwords = yes
# This takes care of the filenames
short preserve case = yes
preserve case = yes
# You might have to adjust the codepage to your country
client code page = 850
# This makes sure your Samba-server is king of the network
os level = 150
After starting Samba (SuSE: ‘rcsamba start’, Debian: ‘/etc/init.d/samba restart’, always as root) you can browse your Network Neighborhood on ‘laptop’ and you will find ‘forty-two’. It does not offer anything yet, but it confirms that we are on the right path.
So, let’s share something! We append the following lines to smb.conf:
[NetSpace]
path = /usr/local/NetSpace
writable = yes
Samba rereads its configuration every minute, so if we change anything, all we have to do is sit and wait 60 seconds to see the effect. The impatient restart the samba-process (not the computer) We also need to set up a Samba-user and the directory. The samba-user is created by ‘smbpasswd -a <username>’ and for directory do a ‘mkdir /usr/local/NetSpace’ but you already knew that, didn’t you?
If we refresh the Windows Network Neighborhood, and click to ‘forty-two’ we will see the share. You can access it directly or map it to a drive-letter as if it was from another Windows-machine. If you cannot create or modify files, you need to modify the permissions on the Unix-side, since if the directory is not writable by the Unix-user, it cannot be changed via samba. Pretty neat, but sometimes confusing.
We can add more shares like the NetSpace-share, for other directories, for the CD-rom and all kind of disk space by adding more sections to smb.conf. If we have more than one person using our computers, we might consider putting a share for each one of them to store personal files. These shares could point to the corresponding home-directories of those users. With a growing number of users, the task of administering such a setup gets harder and harder. So we simply put in the special share ‘[homes]’:
[homes]
read only = No
create mask = 0640
directory mask = 0750
# This means, Samba does not announce the share.
# You have to know what you are looking for.
# (Yes, the implementation of the SEP-Field in computer-science :-)
browseable = No
Refresh your Network Neighborhood and you will find another share which is named like your user. You will not find a share named ‘homes’ though.
Printers are a kind of hardware which are perfectly suitable for sharing in a network, since usually you don’t need them all the time, and they come in very distinct flavors: Fast black-and-white lasers are cheap, the inkjet printers are not quite so fast and a little more expensive, but they print in color. So even if each computer in a network has a printer of his own, there are occasions, when the other’s printer is just better for the job at hand. So, here comes the [printers] section of smb.conf:
[printers]
comment = All Printers
path = /var/tmp
create mask = 0600
printable = Yes
browseable = No
We also have to add a ‘printing = xxx’ into the global-section, to tell samba how our server handles printjobs. xxx is LPRNG for the lprng printing system, BSD for old-style lpr, CUPS for Cups. After Samba has reread its configuration, we are able to see and install the server’s printers as if they were on a Windows-server. If your installation provides multiple print-queues for raw, postscript and ASCII-printing, pick the ‘raw’ queue. On the Windows client, install a suitable driver and you will get the same results as if the printer was connected right to the client. Or pick the postscript-queue and install a postscript driver (Windows supplies those). This is usually slower, since there is an extra translation involved.
So, the Windows clients can access our disks and our printers. But we might want to work the other way around: Using Linux, accessing resources on the Windows-computers. The ‘smbclient’ command comes in handy to find out what Windows has to offer:
stw@forty-two:~> smbclient -U stw -L //Laptop
added interface ip=192.168.0.42 bcast=192.168.0.255 nmask=255.255.255.0
Got a positive name query response from 192.168.0.23 ( 192.168.0.23 )
Password:
Domain=[WORKGROUP] OS=[Windows 5.0] Server=[Windows 2000 LAN Manager]
Sharename Type Comment
--------- ---- -------
E$ Disk Standardfreigabe
IPC$ IPC Remote-IPC
DVD Disk
eh Disk
ADMIN$ Disk Remoteadmin
C$ Disk Standardfreigabe
Server Comment
--------- -------
Workgroup Master
--------- -------
The output tells us that //Laptop is a Win2k-box and offers disk-shares ‘DVD’ and ‘eh’, which (in my case) are the DVD-drive and hard disk partition E: The shares ending with a ‘$’ are system-shares needed by windows. Now we want to use ‘DVD’ and ‘eh’. Using disks means mounting them. We do this by creating the mountpoints and typing:
forty-two:/home/stw # mount -t smbfs -o username=stw //Laptop/DVD /mnt/Laptop/DVD forty-two:/home/stw # mount -t smbfs -o username=stw //Laptop/eh /mnt/Laptop/eh
After supplying the password, both shares are accessible like regular directories.
Printing to a printer which is attached to a Win-box is easy using CUPS. If both CUPS and Samba clients are installed, you can pick ‘Windows printer via samba’ as device and you will be fine. Check the CUPS documentation for details. (The ‘anchor’ for this link has moved in the past. If it does NOT take you to a section called “Printing to Windows Servers”, you need to search that page for it.) Be sure to use the driver suggested by http://www.linuxprinting.org.
This is a lesson provided for free. I have shared my knowledge about Samba as well as I was able to. Yet, there might be mistakes, typos, misunderstanding on my part, omissions and many other things that might cause the information in this document to be wrong.
Security has not been taken in to consideration at all! This document only tries to give readers a start in using Samba in a home environment. Where you go from there is your choice, but if you start using Samba seriously, tighten it up!
Comments and corrections by e-mail are welcome St.Waidele@LinuxBasics.org
But this is now a wiki-page, you might as well improve it yourself :)
Find out how…
Look up the following options for the smb.conf:
and look up information about the following programs:
Copyright (c) by the authors.
Prior to editing, authors agreed to license their contributions by the terms of the GPL.
See our licensing page for details.
Linux® is a registered trademark of Linus Torvalds.