个人工具

Quick HOWTO : Ch11 : Sharing Resources Using Samba

来自Ubuntu中文

Ssfjhh讨论 | 贡献2008年1月16日 (三) 17:45的版本

跳转至: 导航, 搜索


序言

既然你已经安装和运行了Samba,你可能允许用户通过Samba服务器分享软驱,目录,或者打印机等资源。这篇文章会告诉你该怎么做。

== 为Samba PDC添加一台打印机 == 在你的所有计算机之间共享打印机是建立一个家庭网络的优势。这个直接连接打印机和你的PDC的办法不仅使你所有的Windows工作站都能用到打印机,而且能使你的Samba PDC成为一台打印服务器!唯一的潜在限制是你需要在所有网络中Windows客户机上安装打印机驱动。如果是一个很小的家庭网络这没有什么问题,但是如果是一个巨大的团体网络就不太现实。 === 为Linux添加打印机 === 到目前为止,为Linux添加打印机最简单的办法就是用一台基于菜单的可用的打印机(这句不太明白,原文: the easiest way to add a printer in Linux is to use one of the many menu-based printer utilities available.)。 例如:我可以用系统配置打印机(Figure 11-1) ,它非常容易被发现而且可以通过命令行访问。 ==== Figure 11-1 打印机构造屏幕。 ==== Image:samba-print.gif 注意:有时系统配置打印机的图形界面不能按照你预期的那样工作,这取决于环境变量。你可以用命令行临时把必需的变量设置为正确值。
Assuming your printer is locally attached to the parallel port. Here are the steps to use: 假设你想把打印机被放在相应的端口,下面是步骤: # # 移动到下一个按钮可以用tab键,然后 # # # 当“新建一个队列 # ”菜单出现时,给打印机设置一个容易记的名字,选择“本地打印设备”,移动到“下一个”按钮,然后敲回车。 # # 从“安装本地打印 # 设备”菜单中选择“/dev/lp0"假设打印机在并口不支持USB。点击“下一步”按钮到“队列驱动菜单。 # Scroll to your manufacturer's entry, press Enter. Scroll further to your model, and press <Enter> 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. # Move to the "Finish" button and press <Enter>. 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: # Click the "Printers" button # 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. # 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. # 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. # Download the appropriate Windows printer driver from the manufacturer and install it. # Go to the Add Printer menu. Click the Next button. # Select the Network Printer button to access the Local or Network Printer menu. Click the Next button, again. # 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. # 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. # 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. # When the "Add Printer Wizard" appears, select the manufacturer of your printer, select the printer model, and then click OK. # 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 # 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

有时,家庭中的子群成员需要一种更加容易的共享。例如:父母在家庭办公室工作需要一个共享,分发,合作文件的地方,下面


就是步骤。

新建一个目录和一个用户组

正如任何群体活动中,首要的一步是要成立组织。

1. 新建一个Linux parents组:

[root@bigboy tmp]# /usr/sbin/groupadd parents

2. 新建一个目录用以保存这个组的文件。如果一个用户被设为领导者,你可能想改变权限来设置他们的所有者。

[root@bigboy tmp]# mkdir /home/parent-files

[root@bigboy tmp]# chgrp parents /home/parent-files [root@bigboy tmp]# chmod 0770 /home/parent-files

3. 为这个新建的组添加成员。例如:下面的命令可以为这个群组添加一个名为father的成员:

[root@bigboy tmp]# /usr/sbin/usermod -G parents father

 所有的成员都在群组里了,现在他们需要共享。

在SWAT中配置共享

接着,你需要用SWAT在Samba建立中共享。

  1. 点击共享按钮然后输入你想要的共享名称,例如“only parents”。
  2. 点击“新建共享”按钮,路径为/home/parent-files,确定正确的用户名为@parents,parents的是Linux月户组的名字
  3. 点击“提交更改”按钮来新建一个路径为
  4. /etc/samba/smb.conf 的文件
  5. Click on the "Status" tab at the top of the screen and restart
  6. to restart Samba. 点击在屏幕上方的标签“Status(该词不知道该如何翻译)”,然后重启“smbd and nmbd ”来重启Samba。


你的/etc/samba/smb.conf文件末尾应该有像下边一样的条目:

# Parents Shared Area

[only-parents]

path = /home/parent-files

valid users = @parents


如果是,一切正常,你可以继续,如果不是,再次检查你前边几步的工作。

=

用“我的电脑”

映射网络目录

最后,让用户远程登录。

  1. 右键单击桌面上的“我的电脑”图标
  2. 点击“映射网络驱动器”
  3. 选择一个驱动器字母
  4. 浏览
  5. HOMENET域,然后是Samba服务器,最后是名为only-parents的共享
  6. 勾选“登录时重新连接”复选框使设置永远有效。


现在,位于Linux上/home/parent-files目录只能被群组parents访问,你的工作结束了!

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.