个人工具

UbuntuHelp:SettingUpSamba/zh

来自Ubuntu中文

Oneleaf讨论 | 贡献2007年5月30日 (三) 18:15的版本 (新页面: <pre><nowiki> Work in progress (feel free to add notes) And no swear words. "Profanity is the strongest expression of a weak mind!" </nowiki></pre> Anchor(Top) == 什么是Samba...)

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航, 搜索



Work in progress
(feel free to add notes)
And no swear words. "Profanity is the strongest expression of a weak mind!"

Anchor(Top)

什么是Samba,什么情况下我需要用到它?-What is Samba and when do I need it?

attachment:IconsPage/IconSambaShares.png To make a long story short : samba is a set of tools to share files and printers with computers running Windows. It implements the SMB network protocol, which is the heart of Windows networking.

You need samba to :

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

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

  • act as a server for Windows (or samba) clients : share folders and printers, including PDF pseudo-printers so all the computers in your network may write PDF files,
  • 为windows客户机提供网络服务如:文件共享服务、打印服务。它还提供PDF虚拟打印服务,这样所有连接到这台服务器上的windows客户机都可以创建PDF格式的文件了,
  • act as a domain controller in a windows network (authenticating users, etc.)
  • 构建windows网络域控制服务器,用于进行用户权限管理等工作。
  • do some more complex stuff, such as using a windows domain controller to authenticate the users of a linux/un*x machine...
  • 处理其他更为复杂的事务,比如通过windows域控制服务器来管理其他linux/unix主机...

The samba project was started in 1992 by Andrew TRIDGELL. It's now an important piece of software in the linux world when it come to make windows and linux machines interoperate.

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

More information about Samba can be found at http://www.samba.org. Also check out the links at the bottom of this page.

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

Top Back to top

你真的需要Samba吗?也需不是- Do you need Samba? Maybe not:

  • If you want to access shared folders, drives and printers on a Windows computer (that is, act as a client with Windows servers), you only need a smbfs plugin. See MountWindowsSharesPermanently
  • 如果你想使用windows服务器上的共享文件或是共享打印机,(即linux系统作为客户机,windows系统作为服务器),你只需要用到"smbfs"插件就可以了,请查阅 MountWindowsSharesPermanently
  • If you want your Windows computer to be able to use (via a network) a printer that is attached to a Linux computer, you don't need Samba. CUPS can be configured to make the printer accessible to the network. (See the question in the FAQ.)
  • 如果你希望使用其他linux系统上的打印服务,那就不需要用Samba,只需对CUPS稍加配置,让它支持网络打印服务(请参阅: question in the FAQ.)
  • You don't need Samba to share directories between two Linux computers. You can use NFS.
  • 如果你需要使用其他linux系统上的共享文件,那同样也不需要用到Samba,而是使用NFS

Top Back to top

安装Samba-Installing Samba

For installing samba, install the following package: samba (see InstallingSoftware). 安装samba并不复杂,只需要安装名为samba的软件包即可;有关软件的安装请参 ( InstallingSoftware).


Top Back to top

设置你的电脑-Configuring your computer

Start the network configurator using the following menu: 首先启动网络管理器,进行网络设置

Computer -> System Configuration -> Networking


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

Or Ubuntu 5.04 "Hoary Hedgehog" Release: 在 Ubuntu 5.04 "Hoary Hedgehog" 版本下:

System -> Administration -> Networking 系统 -> 管理 -> 网络

attachment:PicNetworkSettings.png

You will need the General tab, in the middle.

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

PicNetworkSettingsPic2.png

Top Back to top

开始设置-Time to fill in your settings:


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>

Note: If you do not know, ask your network-administrator. Typical settings for the workgroup field are "mshome" or "workgroup". 提示:如果你不知道上面这些信息如何填写,请向你的网络管理员咨询,常见的设置是把工作组名设为"mshome"或"workgroup".

The important settings here are your hostname, which should be filled in already, and the domain/workgroup. Press OK on both windows and the first part of cooperating with windows-machines is done. 设置主机名极为重要,通常它会由系统自动填写,工作组名也可能会自动填写。这些信息填写完毕后,点击“OK”退出


You may also edit the file "/etc/samba/smb.conf" manually, and then use "/etc/init.d/samba" to stop and start the service again. 你也可以通过编辑/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:) )))

Top Back to top

Browsing samba shares

Ubuntu and Gnome make it easy to access files on a windows network share.

Open the Computer Menu, then click on "Network". You'll see a "windows network" icon, open it. The next window shows all the domains/workgroups found in your network. Inside each domain/workgroup you get all the computers in it (that is, those sharing something !). Double-click on a computer icon to access its shares and files. Could it be easier ?

Before showing a computer's shares, your system may prompt you for a name and password. Fill in the form with the credentials of a valid user for the computer you're connecting to. You may additionally store that password in your keyring for convenience.

Note: The default installation of Samba does not synchronize passwords. You may have to run "smbpasswd" for each user that needs to have access to his Ubuntu home directory from Microsoft Windows.

Top Back to top

Mounting a samba share

Mounting a share on the local filesystem allows you to work around programs that do not yet use GnomeVFS to browse remote shares transparently. To mount a samba share, first install smbfs:


sudo apt-get update 
sudo apt-get install smbfs

To allow non root accounts to mount shares, change the permissions on the smbmnt program thus:


sudo chmod u+s /usr/bin/smbmnt

The following will mount the myshare folder on myserver to /home/yourusrname/mnt:


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

In order to have a share mounted automatically every time you reboot, you need to do the following:

Open a shell as root


sudo -s

Create a file containing your Windows/Samba user account details:


vi /etc/samba/user

...it should contain two lines as follows:


username = george
password = secret

Change the permissions on the file for security:


chmod 0600 /etc/samba/user

Now create a directory where you want to mount your share (e.g. /mnt/data):


mkdir /mnt/data

Now edit the file system table (/etc/fstab) and add a line as follows:


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

...where 'bob' is the non-root user you log into ubuntu with, 'server' is the name or address of the windows machine and 'share' is the name of the share.

To mount the share now, just use the following command as root. It will mount automatically on subsequent reboots.


mount /mnt/data

to be continued...


Top Back to top

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.

Top Back to top

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.

Top Back to top

Links

Top Back to top


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.

Top Back to top



翻译中 by 雕啸长空