Quick HOWTO : Ch11 : Sharing Resources Using Samba
From Linux Home Networking
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
Error creating thumbnail: Unable to save thumbnail to destination
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:
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:
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.
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.
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.
Next, you need to create the share in Samba using SWAT.
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
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.
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
For Windows 2000
For Windows XP
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]#
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.