Friday, August 3, 2007

Samba resource sharing

Sharing Resources Using Samba
Introduction
Now that you have Samba up and running, you may want to allow users to share such resources such as floppy drives, directories, and printers via the Samba server. This chapter tells you how to do it all.
Adding A Printer To A Samba PDC
Sharing printers amongst all your PCs is one of the advantages of creating a home network. Here's how to connect your printer directly to your PDC Not only does this method make your printer available to all your Windows workstations, it also makes your Samba PDC a print server! The only potential snag is that you need the Windows printer driver loaded on every client machine. This may be okay for a small home network but impractical for a huge corporate network.
Adding The Printer To Linux
By far, the easiest way to add a printer in Linux is to use one of the many menu-based printer utilities available. For the example, I'll use system-config-printer (Figure 11-1), which is easy to find and can be accessed from the command line:
[root@bigboy tmp]# system-config-printer
Figure 11-1 Printer Configuration Screen

Note: Sometimes the graphics in system-config-printer don't work as expected due to your environment variables. You can temporarily set the required variable to the correct the output with the command:
[root@bigboy tmp]# env LANG=C system-config-printer
Assuming your printer is locally attached to the parallel port. Here are the steps to use:
1. Using the tab key, move to the New button and press the Enter key.
2. When the "Create a New Queue" menu appears give the printer name that's easy to remember, select "Local Printer Device" and move to the "next" button before pressing Enter.
3. From the resulting "Setting Up Local Printer Device" menu select /dev/lp0 assuming the printer is on the parallel port as opposed to a USB port. Click the "next" button to go to the "Queue Driver" menu.
4. Scroll to your manufacturer's entry, press Enter. Scroll further to your model, and press again. You'll now get a choice of drivers, select the default device , which is marked with an asterisk (*). Click the "Next" button to go to the "Create a New Queue" menu.
5. Move to the "Finish" button and press . There will be a slight delay.
At this stage, it's wise to do a test print to make sure all is okay.
Make Samba Aware of the Printer
The easiest way to let Samba know the printer is available is via the Samba SWAT Web interface. Once you are in SWAT:
1. Click the "Printers" button
2. Find your printer in the pull-down menu. If the printer name has an asterisk (*) beside it, it has been auto-configured by Samba. It might not be visible on your network, however, if Samba hasn't been restarted since creating the printer. If this is the case, restart Samba. You can now skip ahead to the "Configure the Printer Driver on the Workstations" section.
3. If Samba did not auto-configure your printer, you need to edit or create it yourself. Click on the "Commit Changes" button to create an updated /etc/samba/smb.conf file.
4. Click on the "Status" tab at the top of the screen and restart smbd and nmbd to restart Samba.
Your printer will now be available for use by all Windows workstations.
Configure The Printer Driver On The Workstations
With the printer ready to go on the Linux side, you now need to prepare things in Windows.
1. Download the appropriate Windows printer driver from the manufacturer and install it.
2. Go to the Add Printer menu. Click the Next button.
3. Select the Network Printer button to access the Local or Network Printer menu. Click the Next button, again.
4. You now should be on the Locate Your Printer menu. Don't enter a name, instead click Next so you can browse for your printer.
5. From the Browse for Printer menu, Double-click on the name of your Linux Samba server. You should see the new printer. Click on the printer name, then click Next.
6. You may get the message "The server on which the printer resides does not have the correct printer driver installed. If you want to install the driver on your local computer, click OK." Fortunately, you pre-installed the driver. Click the OK button.
7. When the "Add Printer Wizard" appears, select the manufacturer of your printer, select the printer model, and then click OK.
8. The "Add Printer Wizard" will ask you whether you want to use this new printer as the default printer. Select Yes or No depending on your preference. Click the Next button
9. From the resulting "Completing the Add Printer Wizard" menu, click the Finish button.
The new printer should now show up on the Windows Printers menu in the Control Panel. Send a test print, to be sure all is well.
Creating Group Shares in SAMBA
On occasion, subgroups of a family need a share that is fully accessible by all members of the group. For example, parents working in a home office environment may need a place where they can share, distribute, or collaboratively work on documents. Here's how it's done.
Create The Directory And User Group
As with any group activity, the first step is to get organized.
1. Create a new Linux group parents:
[root@bigboy tmp]# /usr/sbin/groupadd parents
2. Create a new directory for the group's files. If one user is designated as the leader, you might want to change the chown statement to make them owner
[root@bigboy tmp]# mkdir /home/parent-files
[root@bigboy tmp]# chgrp parents /home/parent-files
[root@bigboy tmp]# chmod 0770 /home/parent-files
3. Add the group members to the new group. For instance, the command to add a user named father to the group is:
[root@bigboy tmp]# /usr/sbin/usermod -G parents father
All your members are in the group; now they need to share.
Configure The Share In SWAT
Next, you need to create the share in Samba using SWAT.
1. Click on the shares button then enter the name of the share you want to create, such as only-parents.
2. Click on the "Create Share" button. Make sure the path maps to /home/parent-files and make the valid users be @parents, where parents is the name of the Linux user group.
3. Click on the "Commit Changes" button to create a new /etc/samba/smb.conf file.
4. Click on the "Status" tab at the top of the screen and restart smbd and nmbd to restart Samba.
Your /etc/samba/smb.conf file should have an entry like this at the end:
# Parents Shared Area
[only-parents]
path = /home/parent-files
valid users = @parents
If it does, all is well and you can move on. If not, double check your work in the last steps.
Map The Directory Using "My Computer"
Finally, let the user log into the domain from a remote PC
1. Right click on the "My Computer" icon on the desktop
2. Click on "Map Network Drive"
3. Select a drive letter.
4. Browse to the HOMENET domain, then the Samba server, then the share named only-parents
5. Click on the check box "Reconnect at Logon", to make the change permanent.
Now the files located in the Linux /home/parent-files directory will be accessible to the parents only and your job is complete!
Sharing Windows Drives Using a Linux SAMBA Client
Up to this point I have focused on your Linux server being a Samba server, but it can also mimic a Windows client using Samba's client software.
For example, you can also access a CD-ROM, DVD, ZIP, floppy or hard drive installed on a Windows machine from your Linux box. In this section I'll show you how to share a CD-ROM drive.
Windows Setup
The Windows client box should be setup first as a member of a Samba domain or workgroup. The next step is to make the CD-ROM drive shared. The steps you used depend on which version of Windows you have.
For Windows 98/ME
1. Double click 'My Computer'
2. Right click on the CD-ROM drive and choose 'Sharing'
3. Set the Share Name as 'cdrom' with the appropriate access control
4. Restart windows
For Windows 2000
1. Double click 'My Computer'
2. Right click on the CD-ROM drive and choose 'Sharing'
3. Set the Share Name as 'cdrom' and the appropriate access control
4. Logout and login again as normal using your current login
For Windows XP
1. Double click 'My Computer'
2. Right click on the CD-ROM drive and choose 'Sharing and Properties'
3. Set the Share Name as 'cdrom' and the appropriate access control
4. Logout and login again as normal using your current login
After you have completed this task, you'll have to go to the next step of testing your configuration.
Test Your Windows Client Configuration
Use the smbclient command to test your share. You should substitute the name of your Windows client PC for "WinClient," and in place of "username" provide a valid workgroup/domain username that normally has access to the Windows client. You should get output like this when using the username's corresponding password:
[root@bigboy tmp]# smbclient -L WinClient -U username
added interface ip=192.168.1.100 bcast=192.168.1.255 nmask=255.255.255.0
added interface ip=127.0.0.1 bcast=127.255.255.255 nmask=255.0.0.0
Got a positive name query response from 192.168.1.253 ( 192.168.1.253 )
Password:
Domain=[HOMENET] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]

Sharename Type Comment
--------- ---- -------
IPC$ IPC Remote IPC
D$ Disk Default share
print$ Disk Printer Drivers
SharedDocs Disk
cdrom Disk
Printer2 Printer Acrobat PDFWriter
ADMIN$ Disk Remote Admin
C$ Disk Default share

Server Comment
--------- -------


Workgroup Master
--------- -------
Note: You can get the result with
[root@bigboy tmp]# smbclient -L WinClient -U username%password
But this method is less secure as your password is echoed on the screen.
Create A CD-ROM Drive Mount Point On Your Samba Server
You'll now need to create the mount point on the Linux server to mount and access the CD-ROM drive. In this case, I've named it /mnt/winclient-cdrom, and you'll use the mount command to get access to this device from the Linux server.
Password Prompt Method
The Linux mount command will try to access the CD-ROM device as user "username" by using the "username=" option. You will be prompted for a password.
[root@bigboy tmp]# mkdir /mnt/winclient-cdrom
[root@bigboy tmp]# mount -t smbfs -o username=username \
//winclient/cdrom /mnt/winclient-cdrom
No Prompt Method
Linux won't prompt you for a password if you embed the access password into the mount command string along with username as in the example below.
[root@bigboy tmp]# mkdir /mnt/winclient-cdrom
[root@bigboy tmp]# mount -t smbfs -o \
username=username,password=password \
//winclient/cdrom /mnt/cdrom
Using The smbmount Command Method
Some versions of Linux support the smbmount command to mount the remote drive. Incompatible versions will give errors like this:
[root@bigboy tmp]# smbmount //winclient/cdrom \
/mnt/winclient-cdrom -o username=username
Password:
27875: session setup failed: ERRDOS - ERRnoaccess (Access denied.)
SMB connection failed
To be safe, stick with using the Linux mount command.
Automating Mounting With Linux SAMBA Clients
You can also automate the mounting of shares by placing entries in your /etc/fstab file. In the example below the home directory of user peter on server 192.168.1.100 will be mounted on the /mnt/smb mount point as a samba filesystem (smbfs) using the login information in the file named /etc/cred.
#
# File: /etc/fstab
#
//192.168.1.100/peter /mnt/smb smbfs credentials=/etc/cred 0 0
The contents of the /etc/cred file needs to have the username and password for the account in this format:
#
# File: /etc/cred
#
username = peter
password = peterspassword
Once finished you can use the mount -a to mount the new /etc/fstab entry, and the /mnt/smb directory will now contain the contents of the share.
[root@smallfry tmp]# mount -a
[root@smallfry tmp]# ls /mnt/smb
backups profile docs data music
[root@smallfry tmp]#
Conclusion
Both this chapter and the last have detailed the steps needed to configure a Samba network that is adequate for a small office or home. There are many steps to take, none are particularly complex, but you run the risk of not getting Samba to work if you omit any of them. For this reason, the next chapter is a dedicated troubleshooting guide to help you diagnose and recover from the most common Samba mistakes that we all tend to make.