特殊:Badtitle/NS100:SettingUpSamba/zh:修订间差异

来自Ubuntu中文
跳到导航跳到搜索
Qingshi163留言 | 贡献
无编辑摘要
Qingshi163留言 | 贡献
无编辑摘要
第79行: 第79行:
使用Ubuntu和Gnome可以很容易的访问windows网络共享的文件。
使用Ubuntu和Gnome可以很容易的访问windows网络共享的文件。


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


在显示一台计算机的共享之前,你的系统也许会提醒你输入用户名和秘密。在表单中填入一个有效用户的证明给你要连接到的电脑。为了更方便,你可能另外存储密码在你的钥匙扣。
在显示一台计算机的共享之前,你的系统也许会提醒你输入用户名和秘密。在表单中填入一个有效用户的证明给你要连接到的电脑。为了更方便,你可能另外存储密码在你的钥匙扣。
第85行: 第85行:
注:默认安装的Samba不会同步密码。你也许需要运行“smbpasswd”为每个用户设置从Microsoft Windows访问他的Ubuntu主文件夹的权限。
注:默认安装的Samba不会同步密码。你也许需要运行“smbpasswd”为每个用户设置从Microsoft Windows访问他的Ubuntu主文件夹的权限。


=== 挂载一个samba的共享 === 在一个本地文件夹上挂载一个共享,可以允许你使用周围的一些还没有使用GnomeVFS的程序去清晰的浏览远程的共享。要挂载一个samba的共享,先安装smbfs:
=== 挂载一个samba的共享 ===
 
在一个本地文件夹上挂载一个共享,可以允许你使用周围的一些还没有使用GnomeVFS的程序去清晰的浏览远程的共享。要挂载一个samba的共享,先安装smbfs:
<pre>sudo apt-get update  
<pre>sudo apt-get update  
sudo apt-get install smbfs
sudo apt-get install smbfs
</pre>
</pre>  
要允许没有root权限的帐户挂载共享,更改smbmnt程序的权限,执行:
要允许没有root权限的帐户挂载共享,更改smbmnt程序的权限,执行:
<pre>sudo chmod u+s /usr/bin/smbmnt
<pre>sudo chmod u+s /usr/bin/smbmnt
</pre>
</pre>  
下面会挂载myserver上的myshare文件夹到/home/yourusrname/mnt
下面会挂载myserver上的myshare文件夹到/home/yourusrname/mnt
<pre>smbmount //myserver/myshare /home/yourusrname/mnt
<pre>smbmount //myserver/myshare /home/yourusrname/mnt
</pre>
</pre>  
用命令在你每一次重启自动挂载一个共享,你需要:<br> 用root权限打开一个shell
用命令在你每一次重启自动挂载一个共享,你需要:<br> 用root权限打开一个shell
<pre>sudo -s
<pre>sudo -s
</pre>
</pre>  
创建一个文件控制你的Windows/Samba用户账户:
创建一个文件控制你的Windows/Samba用户账户:
<pre>vi /etc/samba/user
<pre>vi /etc/samba/user
</pre>
</pre>  
它应该想下面一样包含两行:
它应该想下面一样包含两行:
<pre>username = george
<pre>username = george
password = secret
password = secret
</pre>
</pre>  
为了安全,更改该文件的权限:
为了安全,更改该文件的权限:
<pre>chmod 0600 /etc/samba/user
<pre>chmod 0600 /etc/samba/user
</pre>
</pre>  
你想挂载你的共享在哪?创建一个目录(e.g. /mnt.data):
你想挂载你的共享在哪?创建一个目录(e.g. /mnt.data):
<pre>mkdir /mnt/data
<pre>mkdir /mnt/data
</pre>
</pre>  
现在编辑系统文件表(/etc/fstab)添加下面这行:
现在编辑系统文件表(/etc/fstab)添加下面这行:
<pre>//server/share /mnt/data smbfs credentials=/etc/samba/user,rw,uid=bob 0 0
<pre>//server/share /mnt/data smbfs credentials=/etc/samba/user,rw,uid=bob 0 0
</pre>
</pre>  
其中‘bob’是没有root权限登录到ubuntu的,‘server’是Windows机器名称或地址,‘share’是共享的名称。 现在挂载共享,仅仅需要以root权限执行下列命令。以后重启,他将自动挂载。
其中‘bob’是没有root权限登录到ubuntu的,‘server’是Windows机器名称或地址,‘share’是共享的名称。 现在挂载共享,仅仅需要以root权限执行下列命令。以後重启,他将自动挂载。
<pre>mount /mnt/data
<pre>mount /mnt/data
</pre>
</pre>  
继续……
继续……



2008年4月27日 (日) 20:11的版本

{{#ifexist: :SettingUpSamba/zh/zh | | {{#ifexist: SettingUpSamba/zh/zh | | {{#ifeq: {{#titleparts:SettingUpSamba/zh|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:SettingUpSamba/zh|1|-1|}} | zh | | }}

什么是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

继续……

Configuring your computer as a server

The next part does not have a good graphical tool yet, unfortunately, so we must use the command line. It is not difficult, just be careful with typos.

First open a terminal: Applications > System Tools > Terminal and open the file smb.conf


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

How to Save: To save in nano use "ctrl/o" than "ctrl/x".

Tip: Replacing nano with gedit gives you a nice graphical editor.

The file *smb.conf* is divided in several sections:


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

Let's start with Global Settings. Here you will see several lines, which you can also see in the graphical networktool like workgroup and wins server. If you changed everything to your liking already then you can skip this section, if not change to what you need. If you do not know what items mean, leave them be and read `the relevant part in the real samba-howto http://www.samba.org/samba/docs/using_samba/ch06.html` instead of randomly changing them. It will save you trouble-shooting later.

The important part for us is File sharing. We need to change:


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

This describes your /home folder. Usually you want to share this folder in a home-environment, because these are the files you want to share. To do so, make the following changes:


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

This finishes sharing your /home folder. The last thing we need to do is fixing a user.

Add users who can access your shares with the 'smbpasswd' command.


bash:~$ sudo  smbpasswd -a username

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

Reload Samba for every change to users/passwords or 'smb.conf'


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

That's the basis of Samba file-sharing. Please leave your comments about what else is needed here.

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.