个人工具

Quick HOWTO : Ch11 : Sharing Resources Using Samba

来自Ubuntu中文

跳转至: 导航, 搜索


序言

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

== 为Samba PDC添加一台打印机 == 在你的所有计算机之间共享打印机是建立一个家庭网络的优势。这个直接连接打印机和你的PDC的办法不仅使你所有的Windows工作站都能用到打印机,而且能使你的Samba PDC成为一台打印服务器!唯一的潜在限制是你需要在所有网络中Windows客户机上安装打印机驱动。如果是一个很小的家庭网络这没有什么问题,但是如果是一个巨大的团体网络就不太现实。 === 为Linux添加打印机 === 到目前为止,为Linux添加打印机最简单的办法就是将打印机设为默认菜单中能找到的打印机。 例如:我可以用系统配置打印机(Figure 11-1) ,它非常容易被发现而且可以通过命令行访问。 ==== Figure 11-1 打印机构造屏幕。 ==== Image:samba-print.gif 注意:有时系统配置打印机的图形界面不能按照你预期的那样工作,这取决于环境变量。你可以用命令行临时把必需的变量设置为正确值。假设你的打印机是在本地安装的,步骤如下: # # 移动到下一个按钮可以用tab键,然后 # # # 当“新建一个队列 # ”菜单出现时,给打印机设置一个容易记的名字,选择“本地打印设备”,移动到“下一个”按钮,然后敲回车。 # # 从“安装本地打印 # 设备”菜单中选择“/dev/lp0"假设打印机在并口不支持USB。点击“下一步”按钮到“队列驱动菜单。 # 滚动到你打印机的生产商那个空白,按下‘ENTER’键。再继续滚动到你的模型,并且按‘&lt’,再次输入‘&gt’。现在你已经得到了对驱动的选择。接着选择有“*”标记的那个默认装置。点击‘NEXT’可以进入‘创建一个新的队列’菜单。# 移动到‘FINISH’然后按下‘&lt’,输入‘&gt’。这里会稍微有点慢。在这一步,最好能够进行一次打印测试,以确认一切正常。=== 让Samba自己认出打印机 === 让Samba自己认出可用打印机的最简单方法是通过使用‘Samba SWAT Web’界面。一旦你进入了SWAT:#点击‘打印机’按钮 # 在下拉列表中找到你自己的打印机。如果打印机名字旁边有个‘*’,说明Samba已经自动设定过它了。如果Samba在创建打印机后没有重新启动的话,你可能会看不到设定好的打印机。在这种情况下,请重新启动Samba。现在你可以直接跳到‘在工作站上设定打印机驱动’这个项目了。如果Samba没有自动设定你的打印机,你需要自己编辑或者创建一个。点击‘Commit Changes’以创建一个更新过的 /etc/samba/smb.conf 文件。#点击在屏幕顶部的‘Status’标签,并且重启 smbd 和 nmbd 来重新启动Samba。现在你的打印机就可以被整个工作站使用了。 === 在工作站上设定打印机驱动 === 现在你的打印机已经可以在 Linux上运行了,你还需要准备一些事情以便使它能在 Windows上也可以使用。#从打印机生产商那里下载合适的 Windows用驱动,然后安装它。#找到‘添加打印机’菜单,然后点击‘下一步’。 # 选择‘网络打印机’按钮以进入本地或者网络打印机菜单,再次点击‘下一步’。#你现在应该在‘定位你的打印机’菜单这里了,请点击‘下一步’而不要输入名称,这样你就可以浏览你的打印机了。#在’浏览打印机‘菜单中双击你的 Linux Samba服务器的名称。 你应该可以看到新的打印机了,点击打印机的名称,然后点击‘下一步’。#你可能会看到这句话‘服务器上打印机的驱动没有被正确安装,如果你想要在你的机器上安装驱动,点击‘OK’’幸运的是你预装了驱动程序,那就点击‘OK’吧。 # 当‘添加打印机向导’出现时,选择你打印机生产商的名字,打印机型号,然后点击‘OK’。#‘添加打印机向导’会询问你是否想要设此打印机为默认打印机,根据你的喜好选择‘YES’或者‘NO’,点击‘下一步’#在产生的‘完成添加打印机’菜单中点击‘完成’。现在新的打印机应该在控制面板中的‘Windows打印机’菜单中出现了。现在你可以进行打印测试以保证一切顺利。

在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. 点击在屏幕上方的标签“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(用linux SAMBA客户端共享windows驱动)

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.(到此为止,我已经注意到你的linux服务器是一个Samba服务器,但它也可以用Samba的客户端软件模仿windows客户端。)

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.(比如,你也可以从你的linix box中进入一台windows机器上的cd-rom,dvd,软盘或者硬盘。在这一节中,我将向你演示如何共享一个cd-rom驱动器。)

Windows 的建立

windows的客户端首先应该被作为一个samba域或工作组的成员来建立。下一步是共享CD-ROM驱动器。这些步骤取决于您使用的windows版本

对于 Windows 98/ME

  1. 双击 '我的电脑'
  2. 鼠标指向CD-ROM驱动器,单击鼠标右键 ,选择'共享'
  3. 将共享名设置为 'cdrom',并进行适当的访问控制
  4. 重启windows

对于Windows XP

  1. 双击'我的电脑'
  2. 右键点击CD-ROM驱动设备,选择“共享”
  3. 设置共享名为'cdrom',分配适当的存取权限
  4. 注销并用你当前的账号再次登录。

当你完成这个过程后,你必须到下一步测试你的设置。

For Windows 2000

测试你的windows客户端设置

使用smbclient 命令测试你的共享. 你应当用你的Windows客户端名替换‘WinClient’,在'username'处使用一个有效的 工作组/域名 ,它应该能正常访问Windows端。当使用username的相应密码时你应该得到类似于下面的输出。:

[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
--------- -------

注意:你也可以用下面的命令获得结果

[root@bigboy tmp]# smbclient -L WinClient -U username%password

但这个方法缺乏安全性,因为你的密码被回显在屏幕上。

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.