个人工具

UbuntuHelp:SettingUpSamba/zh

来自Ubuntu中文

跳转至: 导航, 搜索

什么是Samba,什么情况下我需要用到它?

attachment:IconsPage/IconSambaShares.png

简单的说,samba是linux系统用来给windows客户机提供文件共享和打印服务的软件,它基于windows网络的核心协议-SMB网络协议。

当你想实现以下目的时,就需要用到samba:

  • 为windows客户机提供网络服务如:文件共享服务、打印服务。它还提供PDF虚拟打印服务,这样所有连接到这台服务器上的windows客户机都可以创建PDF格式的文件了,
  • 构建windows网络域控制服务器,用于进行用户权限管理等工作。
  • 处理其他更为复杂的事务,比如通过windows域控制服务器来管理其他linux/unix主机...

Samba软件开发项目是在1992年由Andrew TRIDGELL.发起的,它现在已经成为linux领域一个其为重要的应用软件,因为它担任着linux和windows互联桥梁的角色.

欲知更多关于samba的信息,请浏览http://www.samba.org. 同样,本文尾部也提供了很多有用的链接.

你真的需要Samba吗?也许不是:

  • 如果你想使用windows服务器上的共享文件或是共享打印机,(即linux系统作为客户机,windows系统作为服务器),你只需要用到"smbfs"插件就可以了,请查阅 MountWindowsSharesPermanently
  • 如果你希望使用其他linux系统上的打印服务,那就不需要用Samba,只需对CUPS稍加配置,让它支持网络打印服务(请参阅: question in the FAQ.)
  • 如果你需要使用其他linux系统上的共享文件,那同样也不需要用到Samba,而是使用NFS

安装Samba

安装samba并不复杂,只需要安装名为samba的软件包即可;有关软件的安装请参 ( InstallingSoftware).


设置你的电脑

首先启动网络管理器,进行网络设置

计算机 -> 系统设置 -> 网络设置

在 Ubuntu 5.04 "Hoary Hedgehog" 版本下:

系统 -> 管理 -> 网络

attachment:PicNetworkSettings.png

你需要设置中间的"General"子页面

PicNetworkSettingsPic2.png

开始设置


Host Settings
Hostname:       <yourcomputer>
Domain name:    <yourdomain>
Windows Networking
Tick Enable windows networking
Description:       <whateveryouwant>
Domain/Workgroup:  <yourdomainorworkgroup>
If you want tick WINS server  <thenameoripaddressofyourwinsserver>

提示:如果你不知道上面这些信息如何填写,请向你的网络管理员咨询,常见的设置是把工作组名设为"mshome"或"workgroup".

设置主机名极为重要,通常它会由系统自动填写,工作组名也可能会自动填写。这些信息填写完毕后,点击“OK”退出

你也可以通过编辑/etc/samba/smb.conf文件来修samba的设置,修改完毕后用/etc/init.d/samba stop/start/resstart/来启用新的配置.

(((Q: I don't have a 'Windows Networking' section, only Hostname and Domain-name. What do I do now?))) ((( Me neither I didnt fill in these details, but followed the rest of the guide and it worked fine:) )))

浏览samba的共享

使用Ubuntu和Gnome可以很容易的访问windows网络共享的文件。

打开“位置”菜单,点击“网络”。你会看见一个“windows网络“的图标,打开它。然後窗口会显示所有在你的网络上找到的域或工作组。进入任意一个域或工作组你会看见所有在此域或工作组的计算机(是指那些分享的东西!)。双击一台计算机的图标就能访问它共享中的文件。它能变得更容易么?

在显示一台计算机的共享之前,你的系统也许会提醒你输入用户名和秘密。在表单中填入一个有效用户的证明给你要连接到的电脑。为了更方便,你可能另外存储密码在你的钥匙扣。

注:默认安装的Samba不会同步密码。你也许需要运行“smbpasswd”为每个用户设置从Microsoft Windows访问他的Ubuntu主文件夹的权限。

挂载一个samba的共享

在一个本地文件夹上挂载一个共享,可以允许你使用周围的一些还没有使用GnomeVFS的程序去清晰的浏览远程的共享。要挂载一个samba的共享,先安装smbfs:

sudo apt-get update 
sudo apt-get install smbfs

要允许没有root权限的帐户挂载共享,更改smbmnt程序的权限,执行:

sudo chmod u+s /usr/bin/smbmnt

下面会挂载myserver上的myshare文件夹到/home/yourusrname/mnt

smbmount //myserver/myshare /home/yourusrname/mnt

用命令在你每一次重启自动挂载一个共享,你需要:
用root权限打开一个shell

sudo -s

创建一个文件控制你的Windows/Samba用户账户:

vi /etc/samba/user

它应该想下面一样包含两行:

username = george
password = secret

为了安全,更改该文件的权限:

chmod 0600 /etc/samba/user

你想挂载你的共享在哪?创建一个目录(e.g. /mnt.data):

mkdir /mnt/data

现在编辑系统文件表(/etc/fstab)添加下面这行:

//server/share /mnt/data smbfs credentials=/etc/samba/user,rw,uid=bob 0 0

其中‘bob’是没有root权限登录到ubuntu的,‘server’是Windows机器名称或地址,‘share’是共享的名称。 现在挂载共享,仅仅需要以root权限执行下列命令。以後重启,他将自动挂载。

mount /mnt/data

继续……

设定你的电脑作为服务器

很不幸,下面的操作没有一个好的图形化工具,所以我们必须使用命令行。它并不困难,仅仅需要小心别打错字。 首先打开一个终端:应用程序>附件>终端,并打开文件smb.conf

sudo nano -w /etc/samba/smb.conf

怎样保存:在nano中先按“ctrl+o”保存,再按“ctrl+x”退出。 提示:用gedit替换nano可以给你一个更好的图形化编辑器。 这个文件(smb.conf)分成几个部分:

Global Settings
Debugging/Accounting
Authentication
Printing
File sharing
Misc
Share Definitions

让我们先从Global Settings开始。你可以看见几行工作组和wins服务器,和图形化网络工具一样。如果你按照你自己的爱好更改好了,那么你就可以跳过这一节,否则你需要。如果你不知道那些条目是什么意思,请先查看samba-howto([1])中的相关部分,而不要随便更改他们。他将为你省去以後的故障排除。
对我们最重要的部分是File sharing。我们需要更改:

![homes]
comment = Home Directories
browseable = no

# By default, the home directories are exported read-only. Change next
# parameter to 'yes' if you want to be able to write to them.
writable = no

# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
create mask = 0700

# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
directory mask = 0700

这描绘你的/home文件夹。在一个家庭环境中,你通常想共享这个文件夹,因为这里有你想分享的档案。要这样作,请作出以下更改:

![homes]
comment = Home Directories
browseable = yes

# By default, the home directories are exported read-only. Change next
# parameter to 'yes' if you want to be able to write to them.
writable = yes

# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
create mask = 0775

# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
directory mask = 0775

共享你的/home文件夹已经完成。下面我们需要固定用户。 使用‘smbpasswd’命令添加可以访问你的共享的用户。

bash:~$ sudo smbpasswd -a username

New SMB password:
Retype new SMB password:
Added user username.

每次更改用户、密码或‘smb.conf’都需要从新载入Samba

bash:~$ sudo /etc/init.d/samba reload

这些都是Samba文件共享的基础。关于这里还需要些什么,请留下你的意见。 Top Back to top

Complicating things a little

We started with the base of samba file-sharing. The above-mentioned items should be enough to get you started. Next we will add details that you might or might not need.

If you have more the one networkcard

If you have more the one networkcard (or interface) then you have to define where you want samba to run. In smb.conf under the [global] section, add:


"interfaces = 127.0.0.1, 192.168.0.31/24"
"bind interfaces only = yes"

The first address (127.0.0.1), is a loopback network connection (it's your own machine). The second address (192.168.0.31), is the address of the card you want samba to run on, the second number (24) is the subnet default for a CLASS-C network. It may vary depending on your network.

With "bind interfaces only" you limit which interfaces on a machine will serve SMB requests.

You can limit which IP address can connect to your Samba server adding these lines:


"hosts allow = 127.0.0.1, 192.168.0.31, 192.168.0.32"
"hosts deny = 0.0.0.0/0"

The loopback address must be present in the first line. The second line deny access from all IP address not in the first line.

Top Back to top

Troubleshooting Samba

A common problem when attempting to access a Samba share from a Windows computer is "System Error 53" after attempting to "Net Use".

The first thing you should do, before looking into your conf files, is ensure that the directory you are sharing actually exists.

Links


Comments

From: -- DamienNozay DateTime(2006-06-17T12:21:58Z):: use this to leave a comment:

From: @ SIG@:: 
<your comment>

From WouterdeVries Sat Dec 4 19:42:39 +0000 2004:: From: Wouter de Vries Date: Sat, 04 Dec 2004 19:42:39 +0000 Subject: shares-admin Message-ID: <20041204194239+0000@https://www.ubuntulinux.org>

You could say something about shares-admin, which lets you add shares to the samba server.

From MaartenJongepier Tue Dec 28 17:06:24 +0000 2004:: From: Maarten Jongepier Date: Tue, 28 Dec 2004 17:06:24 +0000 Subject: smb:// protocol Message-ID: <20041228170624+0000@https://www.ubuntulinux.org>

You doesn't always need samba, isn't is? You can also use smb://windows-compu/share. That works too I thought

Not much here about how to use a Windows printer from Linux. I figured out how to get my Ubuntu machine to access the USB printer (HP LaserJet 1012) on my Windows XP machine, so I'll post that here (at least I will be able to find this when I forget how I did it).

1. Installed the HP LaserJet 1012 on the XP box using the CD that came with the printer.

2. Shared the printer as "LJ1012" (or whatever you want to call it).

3. Created a user named "Guest" (with no password) and added that user under the Security tab for the printer.

4. On Ubuntu, from the command line, entered: sudo adduser cupsys shadow (this is absolutely KEY!!!)

5. Downloaded the best driver (HP-LaserJet_1012-pxl1010.ppd) from linuxprinting.org and copied to /usr/share/cups/model/foomatic-ppds/HP/

6. In Firefox, went to localhost:631 (for Cups)

7. Add Printer - when prompted, logged in as the primary user (my name, not root), with my usual password. This (plus step 4) gets around the problem of there not being a 'root' account in Ubuntu.

8. Chose Windows Printer (Samba) from Add Printer dialogs (way at the bottom of the list).

9. Used the network address smb://guest@WINMACHINE/LJ1012

10. Using the Gnome printer applet, adjusted the paper size to US Letter (applet sometimes freezes, but does not seem to do any harm).

What a PITA, but it WORKED. This printer is a great buy.


From dturnbull Mon Mar 28 07:53:18 +0100 2005:: From: dturnbull Date: Mon, 28 Mar 2005 07:53:18 +0100 Subject: Bleh, had to edit printers.conf Message-ID: <20050328075318+0100@https://www.ubuntulinux.org>

I wanted to use the printer on a Windows system and had no luck with the GUI or the HTTP configuration interfaces. I ended up editing /etc/cups/printers.conf and changing (for example)

DeviceURI smb://WARRIOR/R300
to
DeviceURI smb://GUEST@WARRIOR/R300

After that everything else was configurable from the Gnome GUI. This was in Hoary preview.

From NickIrvine Thu Apr 7 14:03:47 +0100 2005:: From: Nick Irvine Date: Thu, 07 Apr 2005 14:03:47 +0100 Subject: Addition to text Message-ID: <20050407140347+0100@https://www.ubuntulinux.org>

When the text mentions using smbpasswd, it should be noted that the user added as username has to exist as a Linux user as well.

From:me:: What about encrypt passwords = no ? Windows is setup not to use network passwords by default so I think creating a network user is not right.