Linux 下 SMB 的使用
/ns/wz/sys/data/20020821013241.htm
					
最新 Samba 的原始程式可以取得自: 
ftp://nimbus.anu.edu.au/pub/tridge/samba/ 
然而,如果已安装 linux 的 Redhat 版本,你可以使用软体套件{package} 来 
安装它.有些其他版本也包含 Samba 的binaries 
以下两个 daemon 对 Samba 软体套件 是必要的. 它们一般是被安装在 
/usr/sbin ,而可在开机时,从系统起动的 scripts或inetd来执行. 
smbd (The SMB daemon) 
nmbd (提供 NetBIOS nameserver 的支援给 clients) 
一般而言,以下的 Samba 的 binaries 被安装在 /usr/bin, 虽然说它的位置是可选择性. 
smbclient (一种供给 UNIX 机器用的 SMB client{程式}) 
smbprint (一种 script 用在列印於 SMB 主机{host}上的列表机) 
smbprint.sysv (同上, 但是提供给 SVR4 UNIX 机器用的) 
smbstatus (列出对当地主机之目前 SMB 连结情况) 
smbrun (一种 'glue' script 用来简易地执行应用程式於 SMB 主机) 
执行两个 daemon 
这两个 daemon 是 /usr/sbin/smbd 和 /usr/sbin/nmbd. 
你可以执行 Samba daemon 从 inetd 或当成单独的程序. 如果你正设定一个永久档案伺 
服器,你应该从 inetd 来执行,所以如果他们死掉,那将重新开始.如果你只是偶尔想要使 
用 SMB 伺服器,或者用系统管理来辅助,当你需要时,你可以藉由使用 /etc/rc.d/init.d 
script,或甚至直接手动的. 
要从 inetd 来执行 daemon , 请放以下几行在 inetd 组态档, /etc/inetd.conf: 
# SAMBA NetBIOS services (for PC file and print sharing) 
netbios-ssn stream tcp nowait root /usr/sbin/smbd smbd 
netbios-ns dgram udp wait root /usr/sbin/nmbd nmbd 
然後下指令以便重新启动 inetd daemon : 
kill -HUP 1 
要从系统启动的 script 来执行 daemon, 请把以下的 script 置於一个叫做 
/etc/rc.d/init.d/smb 档, 而且 symbolically link 到注释{comments}所说明的档案: 
#!/bin/sh 
# 
# /etc/rc.d/init.d/smb - starts and stops SMB services. 
# 
# The following files should be synbolic links to this file: 
# symlinks: /etc/rc.d/rc1.d/K35smb (Kills SMB services on shutdown) 
# /etc/rc.d/rc3.d/S91smb (Starts SMB services in multiuser mode) 
# /etc/rc.d/rc6.d/K35smb (Kills SMB services on reboot) 
# 
# Source function library. 
. /etc/rc.d/init.d/functions 
# Source networking configuration. 
. /etc/sysconfig/network 
# Check that networking is up. 
[ ${NETWORKING} = "no" ] && exit 0 
# See how we were called. 
case "$1" in 
start) 
echo -n "Starting SMB services: " 
daemon smbd -D 
daemon nmbd -D 
echo 
touch /var/lock/subsys/smb 
;; 
stop) 
echo -n "Shutting down SMB services: " 
killproc smbd 
killproc nmbd 
rm -f /var/lock/subsys/smb 
echo "" 
;; 
*) 
echo "Usage: smb {start|stop}" 
exit 1 
esac 
在 linux (或其他 UNIX机器)上的 Samba 组态设定是被单一档案, /etc/smb.conf ,所控 
制. 这个档决定你想要哪个系统资源分享给外面世界以及你想对他们做什麽限制. 
因为以下章节将会处理分享 linux 磁碟与印表机给 Windows 机器, 本小节所展示的 
smb.conf 档尽量是你所能取得较简单的, 它只是以介绍性为目的. 
目前还不要担心细节部分. 後面的章节将会介绍主要的概念. 
在档案中的每的段落{section}会有个段落标头开始, 其标头像是 [global], [homes], 
[printers] 等等. 
[global] 段落定义一些变数, 而 Samba 将用来定义於所有资源之分享. 
[homes] 段落允许远端使用者来存取在当地(linux)机器上之他们的(且只有他们的) home 
directories{家目录}. 也就是, 如果一个 Windows 使用者从他们的 Windows 机器要设 
法连接到这个分享, 他们将是连接到他们自己个人的 home directiory. 要做这样事情, 
所要注意的是,他们必须在linux box上有个帐号. 
以下的 smb.conf 档案样本允许远端使用者来用当地机器上他们的 home directories 而 
且写到一个暂存的目录. 对一个 Windows 使用者,要想看到这些分享, linux box 必须是 
在区域网路{local network}内. 然後,使用者简单地从 Windows File Manager 或 
Windows Explorer 连接到网路磁碟. 
在以下段落要注意的是, 对这个档之额外项目将会用来允许更多资源被分享. 
; /etc/smb.conf 
; 
; Make sure and restart the server after making changes to this file, ex: 
; /etc/rc.d/init.d/smb stop 
; /etc/rc.d/init.d/smb start 
[global] 
; Uncomment this if you want a guest account 
; guest account = nobody 
log file = /var/log/samba-log.%m 
lock directory = /var/lock/samba 
share modes = yes 
[homes] 
comment = Home Directories 
browseable = no 
read only = no 
create mode = 0750 
[tmp] 
comment = Temporary file space 
path = /tmp 
read only = no 
public = yes 
以上所展示的 smb.conf 样本档, 分享 linux 磁碟给 Windows 使用者是很容易的. 然 
而, 像 Samba 其他的东西, 你可以控制到很大的程度. 以下有些例子 : 
为了分享目录给大家使用, 就建立个类似上述 [tmp] 段落, 亦即加入像这个的东西到 
smb.conf: 
[public] 
comment = Public Stuff 
path = /home/public 
public = yes 
writable = yes 
printable = yes 
为了使以上目录供大众可读取,但只有群组成员{group staff}可写入,请修改其项目像这 
样: 
[public] 
comment = Public Stuff 
path = /home/public 
public = yes 
writable = yes 
printable = no 
write list = @staff 
一种给 UNIX 机器用的 SMB client 程式被包含在 Samba 发行套件之中.它提供一种在命 
令列下的像ftp的介面. 
想要看在给定的主机上有哪些分享可取得, 执行: 
/usr/sbin/smbclient -L host 
这□的 'host' 是你想要浏览的机器名子. 这将会回应一串 'service' 的名称 - 也就 
是, 它所分享给你的磁碟或印表机的名称. 除非 SMB 伺服器没有安全上的设定, 否则它 
将要求你输入密码. 给它 'guest' 帐号的密码或是你个人在那台机器上帐号的密码. 
举个例子: 
smbclient -L zimmerman 
这个指令的输出应该看起来像是这样: 
Server time is Sat Aug 10 15:58:27 1996 
Timezone is UTC+10.0 
Password: 
Domain=[WORKGROUP] OS=[Windows NT 3.51] Server=[NT LAN Manager 3.51] 
Server=[ZIMMERMAN] User=[] Workgroup=[WORKGROUP] Domain=[] 
Sharename Type Comment 
--------- ---- ------- 
ADMIN$ Disk Remote Admin 
public Disk Public 
C$ Disk Default share 
IPC$ IPC Remote IPC 
OReilly Printer OReilly 
print$ Disk Printer Drivers 
This machine has a browse list: 
Server Comment 
--------- ------- 
HOPPER Samba 1.9.15p8 
KERNIGAN Samba 1.9.15p8 
LOVELACE Samba 1.9.15p8 
RITCHIE Samba 1.9.15p8 
ZIMMERMAN 
这个 browse list 列出其他有资源分享给网路的 SMB 伺服器. 
要使用此 client, 请执行: 
/usr/sbin/smbclient service <password> 
这□的 'service' 是一台机器和分享名称. 举例而言,如果你设法连到一台叫做 
zimmerman 的机器上之以 'public' 为分享名称的目录 ,此 service 要叫做 
\\zimmerman\public. 然而,因为 shell 限制, 你会需要脱离 backslashes, 所以你要像 
这样的结束: 
/usr/sbin/smbclient \\\\zimmerman\\public mypasswd 
这样的 'mypasswd' 是你的密码之文字串{literal string}. 
你将会有 smbclient 的提示符号{prompt}出现: 
Server time is Sat Aug 10 15:58:44 1996 
Timezone is UTC+10.0 
Domain=[WORKGROUP] OS=[Windows NT 3.51] Server=[NT LAN Manager 3.51] 
smb: \> 
键入 'h' 取得关於使用 smbclient 的 help: 
smb: \> h 
ls dir lcd cd pwd 
get mget put mput rename 
more mask del rm mkdir 
md rmdir rd prompt recurse 
translate lowercase print printmode queue 
cancel stat quit q exit 
newer archive tar blocksize tarmode 
setmode help ? ! 
smb: \> 
打印机的共享和磁碟机的共享原理是一样的。