请教samba设置

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
mimihu88
帖子: 552
注册时间: 2006-04-03 11:26

请教samba设置

#1

帖子 mimihu88 » 2006-05-26 22:09

刚从5.1转到6.06,设置samba就是不行,和在5 .1的时候一样的设置,死活就看到一个”windows网络“,打开是空的什么都没有,windows也看不到我的ubuntu

难道还有什么要做的

我的security设的是share

我在5.1的时候,samba默认是自启动的,6 .06应该也是的吧?
头像
oliver
帖子: 775
注册时间: 2005-10-05 11:31
联系:

#2

帖子 oliver » 2006-07-11 15:38

同问,6.06如何设置SAMBA呢…… :oops:
头像
wyvern2004
帖子: 70
注册时间: 2005-07-12 20:30
来自: 贵州
联系:

#3

帖子 wyvern2004 » 2006-07-11 17:46

http://weiyw.blog.com.cn
上面有“用samba实现网上邻居”
Xubuntu 7.04 Feisty
NVIDIA GeForce 2 MX/MX 400
Pentium(R) 4 CPU 2.60GHz 1.0G Mem
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
我的博客,欢迎光临!
http://blog.sina.com.cn/dat
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mimihu88
帖子: 552
注册时间: 2006-04-03 11:26

#4

帖子 mimihu88 » 2006-07-11 22:13

[quote="oliver"]同问,6.06如何设置SAMBA呢…… :oops:[/qu

这么老的帖子也翻出来了,我都不记得发过这个帖子,问题早就解决了很简单,看我另外一篇帖子吧

viewtopic.php?t=16115&highlight=%E8%8F% ... C%E9%B8%9F
头像
oliver
帖子: 775
注册时间: 2005-10-05 11:31
联系:

#5

帖子 oliver » 2006-07-12 12:49

mimihu88 写了:
oliver 写了:同问,6.06如何设置SAMBA呢…… :oops:[/qu

这么老的帖子也翻出来了,我都不记得发过这个帖子,问题早就解决了很简单,看我另外一篇帖子吧

viewtopic.php?t=16115&highlight=%E8%8F% ... C%E9%B8%9F
谢谢!可以访问其他windows电脑了,原先我通过“位置”-“网络服务器”浏览没有出现任何局域网内电脑,原来需要自己选择“连接到服务器...”然后输入需要连接的局域网电脑的IP点击连接就能够连入对方的共享文件夹了(纳闷,连帐号和密码都不用输入...) :)

但是,我的Ubuntu却无法出现在windows的工作组计算机中。
按照您的方法我照做了,但是仍然不行。
终端输入:
sudo gedit /etc/samba/smb.conf
做以下修改

security = user前面的“;”去掉

把security=user改为=share
头像
oliver
帖子: 775
注册时间: 2005-10-05 11:31
联系:

#6

帖子 oliver » 2006-07-12 13:03

原来当中有一小段延迟(大概因为用了远程桌面访问的缘故),现在我的计算机已经出现在windows的工作组计算机中,但是双击却无法访问。
出现错误提示:
\\Ubuntu无法访问。您可能没有权限访问网络资源。请与这台服务器的管理员联系以查明您是否有访问权限。
找不到网络路径。
然后我考虑是否因为没有添加远程访问用户的缘故?于是我在终端如下执行:

代码: 全选

oliver@ubuntu:~$ sudo smbpasswd -a oliver
New SMB password:
Retype new SMB password:
oliver@ubuntu:~$
但是问题依旧......


请问该如何解决呢? 谢谢! :)
(这个问题搞定了我就能够用Palm存取计算机上的文件了,呵呵。)
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#7

帖子 bones7456 » 2006-07-13 22:45

oliver 写了:原来当中有一小段延迟(大概因为用了远程桌面访问的缘故),现在我的计算机已经出现在windows的工作组计算机中,但是双击却无法访问。
出现错误提示:
\\Ubuntu无法访问。您可能没有权限访问网络资源。请与这台服务器的管理员联系以查明您是否有访问权限。
找不到网络路径。
然后我考虑是否因为没有添加远程访问用户的缘故?于是我在终端如下执行:

代码: 全选

oliver@ubuntu:~$ sudo smbpasswd -a oliver
New SMB password:
Retype new SMB password:
oliver@ubuntu:~$
但是问题依旧......


请问该如何解决呢? 谢谢! :)
(这个问题搞定了我就能够用Palm存取计算机上的文件了,呵呵。)

对对对,和我的情况一样,希望高手能够帮忙解决一下啊!
dazc
帖子: 2
注册时间: 2006-08-09 15:18

#8

帖子 dazc » 2006-08-11 14:38

bones7456 写了:
oliver 写了:原来当中有一小段延迟(大概因为用了远程桌面访问的缘故),现在我的计算机已经出现在windows的工作组计算机中,但是双击却无法访问。
出现错误提示:
\\Ubuntu无法访问。您可能没有权限访问网络资源。请与这台服务器的管理员联系以查明您是否有访问权限。
找不到网络路径。
然后我考虑是否因为没有添加远程访问用户的缘故?于是我在终端如下执行:

代码: 全选

oliver@ubuntu:~$ sudo smbpasswd -a oliver
New SMB password:
Retype new SMB password:
oliver@ubuntu:~$
但是问题依旧......


请问该如何解决呢? 谢谢! :)
(这个问题搞定了我就能够用Palm存取计算机上的文件了,呵呵。)

对对对,和我的情况一样,希望高手能够帮忙解决一下啊!

我也遇到同样的问题。


我按照http://wiki.ubuntu.org.cn/%E5%85%B1%E4%BA%AB%E5%8F%AA%E8%AF%BB%E4%B8%BB%E6%96%87%E4%BB%B6%E5%A4%B9%EF%BC%88%E9%9C%80%E6%8E%88%E6%9D%83%EF%BC%89
中的方法设置了好几遍,


又参考了其他的设置相关的文章
http://learn.tsinghua.edu.cn:8080/20010 ... .html#sec8
http://myvstar.blog.hexun.com/3894462_d.html
ptopic1011.html


还是无法访问,原先用windows的机器搜索ubuntu的机器,能够搜索到,双击以后,提示说“……无法访问。您可能没有权限访问网络资源。请与这台服务器的管理员联系以查明您是否有访问权限。”


后来设置的连搜索都看不到ubuntu了。

不知道是那里出了问题。

附上我的smb.conf

代码: 全选

#
# Sample configuration file for the Samba suite for Debian GNU/Linux.
#
#
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options most of which 
# are not shown in this example
#
# Any line which starts with a ; (semi-colon) or a # (hash) 
# is a comment and is ignored. In this example we will use a #
# for commentary and a ; for parts of the config file that you
# may wish to enable
#
# NOTE: Whenever you modify this file you should run the command
# "testparm" to check that you have not made any basic syntactic 
# errors. 
#

#======================= Global Settings =======================

[global]

## Browsing/Identification ###

# Change this to the workgroup/NT-domain name your Samba server will part of
   workgroup = WORKGROUP
   display charset = UTF-8
   unix charset = UTF-8
   dos charset = cp936

  netbios name = ubuntu

# server string is the equivalent of the NT Description field
   server string = ubuntu

# Windows Internet Name Serving Support Section:
# WINS Support - Tells the NMBD component of Samba to enable its WINS Server
;   wins support = no

# WINS Server - Tells the NMBD components of Samba to be a WINS Client
# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
;   wins server = w.x.y.z

# This will prevent nmbd to search for NetBIOS names through DNS.
   netbios name = ubuntu
;  dns proxy = no

# What naming service and in what order should we use to resolve host names
# to IP addresses
;   name resolve order = lmhosts host wins bcast

#### Networking ####

# The specific set of interfaces / networks to bind to
# This can be either the interface name or an IP address/netmask;
# interface names are normally preferred
;   interfaces = 127.0.0.0/8 eth0

# Only bind to the named interfaces and/or networks; you must use the
# 'interfaces' option above to use this.
# It is recommended that you enable this feature if your Samba machine is
# not protected by a firewall or is a firewall itself.  However, this
# option cannot handle dynamic or non-broadcast interfaces correctly.
;   bind interfaces only = true



#### Debugging/Accounting ####

# This tells Samba to use a separate log file for each machine
# that connects
   log file = /var/log/samba/log.%m

# Put a capping on the size of the log files (in Kb).
   max log size = 1000

# If you want Samba to only log through syslog then set the following
# parameter to 'yes'.
;   syslog only = no

# We want Samba to log a minimum amount of information to syslog. Everything
# should go to /var/log/samba/log.{smbd,nmbd} instead. If you want to log
# through syslog you should set the following parameter to something higher.
   syslog = 0

# Do something sensible when Samba crashes: mail the admin a backtrace
   panic action = /usr/share/samba/panic-action %d


####### Authentication #######

# "security = user" is always a good idea. This will require a Unix account
# in this server for every user accessing the server. See
# /usr/share/doc/samba-doc/htmldocs/Samba-HOWTO-Collection/ServerType.html
# in the samba-doc package for details.
    security = user
    username map = /etc/samba/smbusers

# You may wish to use password encryption.  See the section on
# 'encrypt passwords' in the smb.conf(5) manpage before enabling.
   encrypt passwords = true

# If you are using encrypted passwords, Samba will need to know what
# password database type you are using.  
   passdb backend = tdbsam

   obey pam restrictions = yes

;   guest account = nobody
   invalid users = root

# This boolean parameter controls whether Samba attempts to sync the Unix
# password with the SMB password when the encrypted SMB password in the
# passdb is changed.
;   unix password sync = no

# For Unix password sync to work on a Debian GNU/Linux system, the following
# parameters must be set (thanks to Ian Kahan <<kahan@informatik.tu-muenchen.de> for
# sending the correct chat script for the passwd program in Debian Sarge).
#   passwd program = /usr/bin/passwd %u
     passwd program = /etc/samba/smbpasswd
   passwd chat = *Enter\snew\sUNIX\spassword:* %n\n *Retype\snew\sUNIX\spassword:* %n\n *password\supdated\ssuccessfully* .

# This boolean controls whether PAM will be used for password changes
# when requested by an SMB client instead of the program listed in
# 'passwd program'. The default is 'no'.
;   pam password change = no

########## Domains ###########

# Is this machine able to authenticate users. Both PDC and BDC
# must have this setting enabled. If you are the BDC you must
# change the 'domain master' setting to no
#
;   domain logons = yes
#
# The following setting only takes effect if 'domain logons' is set
# It specifies the location of the user's profile directory
# from the client point of view)
# The following required a [profiles] share to be setup on the
# samba server (see below)
;   logon path = \\%N\profiles\%U
# Another common choice is storing the profile in the user's home directory
;   logon path = \\%N\%U\profile

# The following setting only takes effect if 'domain logons' is set
# It specifies the location of a user's home directory (from the client
# point of view)
;   logon drive = H:
;   logon home = \\%N\%U

# The following setting only takes effect if 'domain logons' is set
# It specifies the script to run during logon. The script must be stored
# in the [netlogon] share
# NOTE: Must be store in 'DOS' file format convention
;   logon script = logon.cmd

# This allows Unix users to be created on the domain controller via the SAMR
# RPC pipe.  The example command creates a user account with a disabled Unix
# password; please adapt to your needs
; add user script = /usr/sbin/adduser --quiet --disabled-password --gecos "" %u

########## Printing ##########

# If you want to automatically load your printer list rather
# than setting them up individually then you'll need this
;   load printers = yes

# lpr(ng) printing. You may wish to override the location of the
# printcap file
;   printing = bsd
;   printcap name = /etc/printcap

# CUPS printing.  See also the cupsaddsmb(8) manpage in the
# cupsys-client package.
;   printing = cups
;   printcap name = cups

# When using [print$], root is implicitly a 'printer admin', but you can
# also give this right to other users to add drivers and set printer
# properties
;   printer admin = @lpadmin


############ Misc ############

# Using the following line enables you to customise your configuration
# on a per machine basis. The %m gets replaced with the netbios name
# of the machine that is connecting
;   include = /home/samba/etc/smb.conf.%m

# Most people will find that this option gives better performance.
# See smb.conf(5) and /usr/share/doc/samba-doc/htmldocs/speed.html
# for details
# You may want to add the following on a Linux system:
#         SO_RCVBUF=8192 SO_SNDBUF=8192
   socket options = TCP_NODELAY

# The following parameter is useful only if you have the linpopup package
# installed. The samba maintainer and the linpopup maintainer are
# working to ease installation and configuration of linpopup and samba.
;   message command = /bin/sh -c '/usr/bin/linpopup "%f" "%m" %s; rm %s' &

# Domain Master specifies Samba to be the Domain Master Browser. If this
# machine will be configured as a BDC (a secondary logon server), you
# must set this to 'no'; otherwise, the default behavior is recommended.
;   domain master = auto

# Some defaults for winbind (make sure you're not using the ranges
# for something else.)
;   idmap uid = 10000-20000
;   idmap gid = 10000-20000
;   template shell = /bin/bash

#======================= Share Definitions =======================

# Un-comment the following (and tweak the other settings below to suit)
# to enable the default home directory shares.  This will share each
# user's home directory as \\server\username
;[homes]
;    comment = Home Directories
;    browseable = no

# By default, \\server\username shares can be connected to by anyone
# with access to the samba server.  Un-comment the following parameter
# to make sure that only "username" can connect to \\server\username
;   valid users = %S

# 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 0600 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0664.
;   create mask = 0600

# 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

# Un-comment the following and create the netlogon directory for Domain Logons
# (you need to configure Samba to act as a domain controller too.)
;[netlogon]
;    comment = Network Logon Service
;    path = /home/samba/netlogon
;    guest ok = yes
;    writable = no
;    share modes = no

# Un-comment the following and create the profiles directory to store
# users profiles (see the "logon path" option above)
# (you need to configure Samba to act as a domain controller too.)
# The path below should be writable by all users so that their
# profile directory may be created the first time they log on
;[profiles]
;   comment = Users profiles
;   path = /home/samba/profiles
;   guest ok = no
;   browseable = no
;   create mask = 0600
;   directory mask = 0700

;wins support = no
;[printers]
;   comment = All Printers
;   browseable = no
;   path = /tmp
;   printable = yes
;   public = no
;   writable = no
;   create mode = 0700

# Windows clients look for this share name as a source of downloadable
# printer drivers
;[print$]
;   comment = Printer Drivers
;   path = /var/lib/samba/printers
;   browseable = yes
;   read only = yes
;   guest ok = no
# Uncomment to allow remote administration of Windows print drivers.
# Replace 'ntadmin' with the name of the group your admin users are
# members of.
;   write list = root, @ntadmin

# A sample share for sharing your CD-ROM with others.
;[cdrom]
;   comment = Samba server's CD-ROM
;   writable = no
;   locking = no
;   path = /cdrom
;   public = yes

# The next two parameters show how to auto-mount a CD-ROM when the
#	cdrom share is accesed. For this to work /etc/fstab must contain
#	an entry like this:
#
#       /dev/scd0   /cdrom  iso9660 defaults,noauto,ro,user   0 0
#
# The CD-ROM gets unmounted automatically after the connection to the
#
# If you don't want to use auto-mounting/unmounting make sure the CD
#	is mounted on /cdrom
#
;   preexec = /bin/mount /cdrom
;   postexec = /bin/umount /cdrom


[Share]
comment = Shared Folder
path = /home/zach/share
public = yes
writable = yes
valid users = loyalty
create mask = 0700
directory mask = 0700
force user = nobody
force group = nogroup
available = yes
browseable = yes
为这事倒腾两天了,头都大了~~
头像
lvjinhua
帖子: 436
注册时间: 2006-02-23 14:46
来自: 上海
联系:

#9

帖子 lvjinhua » 2006-08-14 22:58

我也想知道原因!
====
dubuntu-6.06-livecd-i386正式版正式完工!
====
*支持LiveCD硬盘启动
*Linux 2.6.15-23-686
*永中Office 2007
*LumaQQ+OpenQ+cycloneQQ
**N 多的编程及调试工具**
zhuzhzh
帖子: 265
注册时间: 2005-07-28 15:08

#10

帖子 zhuzhzh » 2006-08-15 13:35

同样是权限问题啊
无声胜有声
头像
toomanystars
帖子: 168
注册时间: 2006-09-12 17:01

这个也许有用

#11

帖子 toomanystars » 2006-09-26 0:40

viewtopic.php?t=20852&highlight=samba

按照这个帖子设置,刚开始在Windows下也提示没有权限,但在地址栏中输入//ip,就可以了!

如果还有更多问题,可以参考这里:
http://www.linuxsir.org/main/?q=node/158#0.3

索性贴过来:

一步一学Linux与Windows 共享文件Samba (v0.2b)

作者:北南南北,正在增加中... ... 需要您的参与;
来自:LinuxSir.Org
简介:本文只是讲一讲我们最常用的Linux与Windows共享文件,主要是为新手指一指路。如何建立最简单的Samba服务器,并讲述遇到问题应该从何处寻找解决方案;正在更新之中,希望您的参加 ... ... 谢谢;

目录

0、架设Samba 服务器的前提;
0.1 查看文件内容和编辑文件的工具;
0.2 关于文件和目录相关;
03 用户和用户组相关;
04 进程管理;

1 Samba 简介
2 Samba 功能和应用范围
3 Samba 两个服务器相关启动程序、客户端及服务器配置文件等;
3.1 Samba 有两个服务器,一个是smbd,另一个是nmbd;
3.2 查看Samba 服务器的端口及防火墙;
3.3 查看Samba 服务器的配置文件;
3.4 Samba 在Linux 中的一些工具(服务器端和客户端);
3.5 在Linux 中的常用工具,Windows查看Linux共享的方法 ;
3.5.1 在Linux系统中查看网络中Windows共享文件及Linux中的Samba共享文件;
3.5.2 在Windows中访问Linux Samba服务器共享文件的办法;
3.5.3 smbfs文件系统的挂载;

4 由最简单的一个例子说起,匿名用户可读可写的实现;
第一步: 更改smb.conf
第二步:建立相应目录并授权;
第三步:启动smbd和nmbd服务器;
第四步:查看smbd进程,确认Samba 服务器是否运行起来了;
第五步:访问Samba 服务器的共享;

5、复杂一点的用户共享模型(适合10人左右的小型企业);
5.1 共享权限设计实现的功能;
5.2 在服务器上创建相应的目录;
5.3 添加用户用户组,设置相应目录家目录的权限;
5.3.1 添加用户组;
5.3.2 添加用户;
5.3.3 添加samba用户,并设置密码;
5.3.4 配置相关目录的权限和归属;

5.4 修改Samba配置文件;
5.5 关于客户端访问;
5.5.1 Windows客户端访问;




++++++++++++++++++++++++++++++++++++++++++++++++
正文
++++++++++++++++++++++++++++++++++++++++++++++++


0、架设Samba 服务器的前提;

Linux是一个多用户的操作系统,对任何服务器的架设与都用户、用户组及权限相关,这是操作的基础。Samba服务器也不例外,对这些知识的掌握也是极为重要的。在Windows系统上虽然也能架共享文件服务器,但它的权限控制实在令人不敢恭维。如果我们用Windows系统来架网络共享文件系统,就是点鼠标也能把我们点迷糊了。但在Linux中,我们可以轻松的改一改配置文件,不到几分钟就能建好自己的Samba服务器。哪个更容易,只有你知道;

对于Samba服务器的架设,有的弟兄简单的认为,只要把改一下配置文件,创建好相应的目录就行了。其实并不是这样的,还要深入的工作,比如目录的权限和归属,也就是说能让哪个用户和用户组有读写权。只有把配置文件和共享目录的权限结合起来,才能架好Samba服务器;

下面是常用的基础知识,我们在本文中所涉及的内容都可以在下面的列表中找到相应的解释;


0.1 查看文件内容和编辑文件的工具;

《Linux 文件内容查看工具介绍》
《文件编辑器 vi》


0.2 关于文件和目录相关;

《Linux 文件类型 及文件的扩展名》
《Linux 文件和目录管理之列出、删除、复制、移动及改名》
《Linux 文件和目录的属性》
《简述Linux文件搜索》


03 用户和用户组相关;

《Linux 用户(user)和用户组(group)管理概述》
《用户(User)和用户组(Group)配置文件详解》
《Linux 用户管理工具介绍》
《Linux 用户(User)查询篇》


04 进程管理;

《Linux 进程管理》

1 Samba 简介

Samba(SMB是其缩写) 是一个网络服务器,用于Linux和Windows共享文件之用;Samba 即可以用于Windows和Linux之间的共享文件,也一样用于Linux和Linux之间的共享文件;不过对于Linux和Linux之间共享文件有更好的网络文件系统NFS,NFS也是需要架设服务器的;

大家知道在Windows 网络中的每台机器即可以是文件共享的服务器,也可以同是客户机;Samba 也一样能行,比如一台Linux的机器,如果架了Samba Server 后,它能充当共享服务器,同时也能做为客户机来访问其它网络中的Windows共享文件系统,或其它Linux的Sabmba 服务器;

我们在Windows网络中,看到共享文件功能知道,我们直接就可以把共享文件夹当做本地硬盘来使用。在Linux的中,就是通过Samba的向网络中的机器提供共享文件系统,也可以把网络中其它机器的共享挂载在本地机上使用;这在一定意义上说和FTP是不一样的。

Samba 用的netbios协议,如果您用Samba 不成功,

Linux与Windows 、Linux 和 Linux

2 Samba 功能和应用范围

Samba 应该范围主要是Windows和Linux 系统共存的网络中使用;如果一个网络环境都是Linux或Unix类的系统,没有必要用Samba,应该用NFS更好一点;

那Samba 能为我们提供点什么服务呢?主要是共享文件和共享打印机;

3 Samba 两个服务器相关启动程序、客户端及服务器配置文件等;

3.1 Samba 有两个服务器,一个是smb,另一个是nmb;

smb 是Samba 的主要启动服务器,让其它机器能知道此机器共享了什么;如果不打开nmb服务器的话,只能通过IP来访问,比如在Windows的IE浏览器上打入下面的一条来访问;


\\192.168.1.5\共享目录
\\192.168.1.5\opt



而nmb是解析用的,解析了什么呢?就是把这台Linux机器所共享的工作组及在此工作组下的netbios name解析出来;

一般的情况下,在RPM包的系统,如果是用RPM包安装的Samba ,一般可以通过如下的方式来启动Samba服务器;


[root@localhost ~]# /etc/init.d/smb start
启动 SMB 服务: [ 确定 ]
启动 NMB 服务: [ 确定 ]



如果停止呢?就在smb后面加stop ;重启就是restart


[root@localhost ~]# /etc/init.d/smb stop
[root@localhost ~]# /etc/init.d/smb restart


对于所有系统来说,通用的办法就是直接运行smb 和nmb;当然您要知道smb和nmb所在的目录才行;如果是自己编译的Samba ,您应该知道您把Samba放在哪里了;


[root@localhost ~]# /usr/sbin/smbd
[root@localhost ~]# /usr/sbin/nmbd



查看服务器是否运行起来了,则用下面的命令;

[root@localhost ~]# pgrep smbd
[root@localhost ~]# pgrep nmbd


关掉Samba服务器,也可以用下面的办法,大多是通用的;要root权限来执行;


[root@localhost ~]# pkill smbd
[root@localhost ~]# pkill nmbd


3.2 查看Samba 服务器的端口及防火墙;

查看这个有何用呢?有时你的防火墙可能会把smbd服务器的端口封掉,所以我们应该smbd服务器所占用的端口;下面查看中,我们知道smbd所占用的端口是139和445 ;

[root@localhost ~]# netstat -tlnp |grep smb
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 10639/smbd
tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 10639/smbd

如果您有防火墙,一定要把这两个端口打开。如果不知道怎么打开。可能你和我一样是新手,还是把防火墙规则清掉也行;

[root@localhost ~]# iptables -F

[root@localhost ~]# /sbin/iptables -F

3.3、查看Samba 服务器的配置文件;

如果我们是用Linux发行版自带的Samba软件包,一般情况下Samba服务器的配置文件都位于/etc/samba目录中,服务器的主配置文件是smb.conf;也有有户配置文件 smbpasswd、smbusers和lmhosts等(最好您查看一下这些文件的内容);还有一个文件是secrets.tdb,这个文件是 Samba 服务器启动手自动生成的;我们慢慢根据教程的进度来适当地增加这些文件的说明吧;一下子都说出来,感觉内容太多;所以只能一点一点的来了;

3.4、Samba 在Linux 中的一些工具(服务器端和客户端);

smbcacls smbcontrol smbencrypt smbmount smbprint smbstatus smbtree
smbclient smbcquotas smbmnt smbpasswd smbspool smbtar smbumount
smbd nmbd mount



其中服务器端的是smbd、nmbd、smbpasswd ;其它的大多是客户端;这些并不是都需要一定要精通的,但至少得会用几个;比如smbmount(也就是mount 加参数的用法),还用smbclient等;

3.5 在Linux 中的常用工具mount(smbmount)和smbclient;Windows查看Linux共享的方法 ;

3.5.1 在Linux系统中查看网络中Windows共享文件及Linux中的Samba共享文件;

一般的情况下,我们要用到smbclient;常用的用法也无非是下面的;


[root@localhost ~]# smbclient -L //ip地址或计算机名

smbclient 是Samba 的Linux 客户端,在Linux机器上用来查看服务器上的共享资源,也可以象FTP一样,用户可以登录Samba服务器,也可以上传put和下载get文件,遗憾的是对中文支持并不友好;

查看服务器上的资源;

smbclient -L //IP [-U 用户名]

如果您的Samba服务器配置为user模式,就要加 “-U 用户名“,如果是share模式,省略也可;

比如:

[root@localhost ~]# smbclient -L //192.168.1.3 -U sir01
Password: 请输入用户sir01的密码

如果您是用share模式,就可以不必理会用户和密码,直接用;

[root@localhost ~]# smbclient -L //192.168.1.3
Password: 直接按回车

登录用户身份Samba服务器共享

以用户身份登录共享后,能象FTP用户一样,下传和下载文件;用put表示上传,用get表示下载;

smbclient //IP地址/共享文件夹 -U 用户

说明:IP地址大家都知道,你不知道自己的IP地址,可以用/sbin/ifconfig 来查看; 共享文件夹是我们在smb.conf中定义的[共享文件夹],比如[sir01]。-U 用户名表示Samba 的用户;

比如:

[root@localhost ~]# smbclient //192.168.1.3/sir01 -U sir01
Password:
Domain=[LINUXSIR] OS=[Unix] Server=[Samba 3.0.21b-2]
smb: \> ls

说明:登录到Samba服务器上,就可以用smbclient的一些指令,可以象用FTP指令一样上传和下载文件;

smbclient 命令说明

命令 说明

?或help [command] 提供关于帮助或某个命令的帮助
![shell command] 执行所用的SHELL命令,或让用户进入 SHELL提示符
cd [目录] 切换到服务器端的指定目录,如未指定,则 smbclient 返回当前本地目录
lcd [目录] 切换到客户端指定的目录;
dir 或ls 列出当前目录下的文件;
exit 或quit 退出smbclient
get file1 file2 从服务器上下载file1,并以文件名file2存在本地机上;如果不想改名,可以把file2省略
mget file1 file2 file3 filen 从服务器上下载多个文件;
md或mkdir 目录 在服务器上创建目录
rd或rmdir 目录 删除服务器上的目录
put file1 [file2] 向服务器上传一个文件file1,传到服务器上改名为file2;
mput file1 file2 filen 向服务器上传多个文件

3.5.2 在Windows中访问Linux Samba服务器共享文件的办法;

这个简单吧,在网上领居,查看工作组就能看得到,或者在浏览器上输入如下的


\\ip地址或计算机名

这样就能看到这个机器上有什么共享的了,点鼠标操作完成;如果访问不了,不要忘记把Linux的防火墙规划清掉,或让相应的端口通过;

3.5.3 在Linux中smbfs文件系统的挂载;

mount 的用法,加载网络中的共享文件夹到本地机;mount就是用于挂载文件系统的,SMB做为网络文件系统的一种,也能用mount挂载;smbmount说到底也是用mount的一个变种;

mount 挂载smbfs的用法;

mount -t smbfs -o codepage=cp936,username=用户名,password=密码 , -l //ip地址/共享文件夹名 挂载点

mount -t smbfs -o codepage=cp936,username=用户名,password=密码 , -l //计算机名/共享文件夹名 挂载点

mount -t smbfs -o codepage=cp936 //ip地址或计算机名/共享文件夹名 挂载点



smbmount的用法:
smbmount -o username=用户名,password=密码 , -l //ip地址或计算机名/共享文件夹名 挂载点
smbmount //ip地址或计算机名/共享文件夹名 挂载点



说明:

如果您的服务器是以share共享的,则无需用户名和密码就能挂载,如果出现要密码的提示,直接回车就行;您也可以用smbmount 来挂载,这样就无需用mount -t smbfs来指定文件系统的类型了;

对于挂载点,我们要自己建立一个文件夹,比如我们可以建在/opt/smbhd,这由您说的算吧;

在mount的命令中,我们发现有这样的一个参数codepage=cp936,这是服务器端文件系统的编码的指定,cp936 就是简体中文,当然您可以用utf8等,尝试一下吧。

如果您挂载了远程的smbfs文件系统出现的是简体中文乱码,就要考虑挂载时要指定编码了;

4、由最简单的一个例子说起,匿名用户可读可写的实现;

第一步: 更改smb.conf

我们来实现一个最简单的功能,让所有用户可以读写一个Samba 服务器共享的一个文件夹;我们要改动一下smb.conf ;首先您要备份一下smb.conf文件;

[root@localhost ~]# cd /etc/samba
[root@localhost samba]# mv smb.conf smb.confBAK

然后我们来重新创建一个smb.conf文件;


[root@localhost samba]#touch smb.conf


然后我们把下面这段写入smb.conf中;

[global]
workgroup = LinuxSir
netbios name = LinuxSir05
server string = Linux Samba Server TestServer
security = share
[linuxsir]
path = /opt/linuxsir
writeable = yes
browseable = yes
guest ok = yes



注解:

[global]这段是全局配置,是必段写的。其中有如下的几行;

workgroup 就是Windows中显示的工作组;在这里我设置的是LINUXSIR (用大写);
netbios name 就是在Windows中显示出来的计算机名;
server string 就是Samba服务器说明,可以自己来定义;这个不是什么重要的;
security 这是验证和登录方式,这里我们用了share ;验证方式有好多种,这是其中一种;另外一种常用的是user的验证方式;如果用share呢,就是不用设置用户和密码了;

[linuxsir] 这个在Windows中显示出来是共享的目录;
path = 可以设置要共享的目录放在哪里;
writeable 是否可写,这里我设置为可写;
browseable 是否可以浏览,可以;可以浏览意味着,我们在工作组下能看到共享文件夹。如果您不想显示出来,那就设置为 browseable=no

guest ok 匿名用户以guest身份是登录;

第二步:建立相应目录并授权;

[root@localhost ~]# mkdir -p /opt/linuxsir
[root@localhost ~]# id nobody
uid=99(nobody) gid=99(nobody) groups=99(nobody)
[root@localhost ~]# chown -R nobody:nobody /opt/linuxsir



注释:关于授权nobody,我们先用id命令查看了nobody用户的信息,发现他的用户组也是nobody,我们要以这个为准。有些系统nobody用户组并非是nobody ;

第三步:启动smbd和nmbd服务器;

[root@localhost ~]# smbd
[root@localhost ~]# nmbd

第四步:查看smbd进程,确认Samba 服务器是否运行起来了;



[root@localhost ~]# pgrep smbd
13564
13568



第五步:访问Samba 服务器的共享;


在Linux 中您可以用下面的命令来访问;
[root@localhost ~]# smbclient -L //LinuxSir05
Password: 注:直接按回车



在Windows中,您可以用下面的办法来访问;


\\LinuxSir05\


5、复杂一点的用户共享模型(适合10人左右的小型企业);

比如一个公司有五个部门,分别是linuxsir,sir01,sir02,sir03,sir04。我们想为这家公司设计一个比较安全的共享文件模型。每个用户都有自己的网络磁盘,sir01到sir04还有共用的网络硬盘;所有用户(包括匿名用户)有一个共享资料库,此库为了安全是只读的;所有的用户(包括匿名用户)要有一个临时文件终转的文件夹... ....


5.1 共享权限设计实现的功能;

1)linuxsir部门具有管理所有SMB空间的权限;
2)sir01到sir04拥有自己的空间,并且除了自身及linuxsir有权限以外,对其它用户具有绝对隐私性;
3)linuxsir01到linuxsir04拥有一个共同的读写权限的空间;
4) 所有用户(包括匿名用户)有一个有读权限的空间,用于资料库,所以不要求写入数据。
5)sir01到sir04还有一个共同的空间,对sir01到sir04的用户来说是隐私的,不能让其它用户来访问。
6) 还要有一个空间,让所有用户可以写入,能删除等功能,在权限上无限制 ,用于公司所有用户的临时文档终转等;


5.2 在服务器上创建相应的目录;

[root@localhost ~]# mkdir -p /opt/linuxsir
[root@localhost ~]# cd /opt/linuxsir
[root@localhost linuxsir]# mkdir sir01 sir02 sir03 sir04 sirshare sir0104rw sirallrw
[root@localhost linuxsir]# ls
sir01 sir0104rw sir02 sir03 sir04 sirallrw sirshare

注:功用如下:

/opt/linuxsir 这是管理员目录,负责管理其下所有目录;
/opt/linuxsir/sir01 是sir01的家目录,用于私用,除了用户本身和linuxsir以外其它用户都是不可读不可写;
/opt/linuxsir/sir02 是sir02的家目录,用于私用,除了用户本身和linuxsir以外其它用户都是不可读不可写;
/opt/linuxsir/sir03 是sir03的家目录,用于私用,除了用户本身和linuxsir以外其它用户都是不可读不可写;
/opt/linuxsir/sir04 是sir04的家目录,用于私用,除了用户本身和linuxsir以外其它用户都是不可读不可写;
/opt/linuxsir/sirshare 所用用户(除了linuxsir有权限写入外)只读目录
/opt/linuxsir/sir0104rw 是用于sir01到sir04用户可读可写共用目录,但匿名用户不能读写;
/opt/linuxsir/sirallrw 用于所有用户(包括匿名用户)的可读可写;


5.3 添加用户用户组,设置相应目录家目录的权限;


5.3.1 添加用户组;

[root@localhost ~]# /usr/sbin/groupadd linuxsir
[root@localhost ~]# /usr/sbin/groupadd sir01
[root@localhost ~]# /usr/sbin/groupadd sir02
[root@localhost ~]# /usr/sbin/groupadd sir03
[root@localhost ~]# /usr/sbin/groupadd sir04
[root@localhost ~]# /usr/sbin/groupadd sir0104


5.3.2 添加用户;

[root@cuc03 ~]# adduser -g sir01 -G sir0104 -d /opt/linuxsir/sir01 -s /sbin/nologin sir01
[root@cuc03 ~]# adduser -g sir02 -G sir0104 -d /opt/linuxsir/sir02 -s /sbin/nologin sir02
[root@cuc03 ~]# adduser -g sir03 -G sir0104 -d /opt/linuxsir/sir03 -s /sbin/nologin sir03
[root@cuc03 ~]# adduser -g sir04 -G sir0104 -d /opt/linuxsir/sir04 -s /sbin/nologin sir04
[root@cuc03 ~]# adduser -g linuxsir -d /opt/linuxsir -G linuxsir,sir01,sir02,sir03,sir04,sir0104 -d /opt/linuxsir -s /sbin/nologin linuxsir

为什么这样添加用户?请参考:

《Linux 文件和目录的属性》
《Linux 用户管理工具介绍》

当然我们还得学会查看用户信息的工具用法,比如 用finger和id来查看用户信息,主要是看用户是否添加正确;比如;请参考《Linux 用户(User)查询篇》

[root@localhost ~]# id linuxsir
[root@localhost ~]# finger linuxsir


5.3.3 添加samba用户,并设置密码;

我们用的方法是先添加用户,但添加的这些用户都是虚拟用户,因为这些用户是不能通过SHELL登录系统的;另外值得注意的是系统用户密码和 Samba用户的密码是不同的。如果您设置了系统用户能登入SHELL,可以设置用户的Samba密码和系统用户通过SHELL登录的密码不同。

我们通过smbpasswd 来添加Samba用户,并设置密码。原理是通过读取/etc/passwd文件中存在的用户名。

[root@localhost sir01]# smbpasswd -a linuxsir
New SMB password: 注:在这里添加Samba用户linuxsir的密码;
Retype new SMB password: 注:再输入一次;

用同样的方法来添加 sir01、sir02、sir03、sir04的密码;


5.3.4 配置相关目录的权限和归属;

[root@cuc03 ~]# chmod 755 /opt/linux
[root@cuc03 ~]# chown linuxsir:linuxsir /opt/linuxsir
[root@cuc03 ~]# cd /opt/linuxsir
[root@cuc03 ~]# chmod 2770 sir0*
[root@cuc03 ~]# chown sir01.linuxsir sir01
[root@cuc03 ~]# chown sir02.linuxsir sir02
[root@cuc03 ~]# chown sir03.linuxsir sir03
[root@cuc03 ~]# chown sir04.linuxsir sir04
[root@cuc03 ~]# chown linuxsir.sir0104 sir0104rw
[root@cuc03 ~]# chown linuxsir.linuxsir sirshare
[root@cuc03 ~]# chmod 755 sirshare
[root@cuc03 ~]# chown linuxsir:linuxsir sirallrw
[root@cuc03 ~]# chmod 3777 sirallrw


5.4 修改Samba配置文件 smb.conf;

配置文件如下,修改/etc/samba/smb.conf后,不要忘记重启smbd和nmbd服务器;

[global]
workgroup = LINUXSIR
netbios name = LinuxSir
server string = Linux Samba Test Server
security = share
[linuxsir]
comment = linuxsiradmin
path = /opt/linuxsir/
create mask = 0664
#create mask是用户创建文件时的权限掩码;对用户来可读可写,对用户组可读可写,对其它用户可读;
directory mask = 0775
#directory mask 是用来设置用户创建目录时的权限掩码,意思是对于用户和用户组可读可写,对其它用户可读可执行;
writeable = yes
valid users = linuxsir
browseable = yes
[sirshare]
path = /opt/linuxsir/sirshare
writeable = yes
browseable = yes
guest ok = yes
[sirallrw]
path = /opt/linuxsir/sirallrw
writeable = yes
browseable = yes
guest ok = yes
[sir0104rw]
comment = sir0104rw
path = /opt/linuxsir/sir0104rw
create mask = 0664
directory mask = 0775
writeable = yes
valid users = linuxsir,@sir0104
#@sir0104是用户组;
browseable = yes
[sir01]
comment = sir01
path = /opt/linuxsir/sir01
create mask = 0664
directory mask = 0775
writeable = yes
valid users = sir01,@linuxsir
browseable = yes
[sir02]
comment = sir02
path = /opt/linuxsir/sir02
create mask = 0664
directory mask = 0775
writeable = yes
valid users = sir02,@linuxsir
browseable = yes
[sir03]
comment = sir03
path = /opt/linuxsir/sir03
create mask = 0664
directory mask = 0775
writeable = yes
valid users = sir03,@linuxsir
browseable = yes
[sir04]
comment = sir04
path = /opt/linuxsir/sir04
create mask = 0664
directory mask = 0775
writeable = yes
valid users = sir04,@linuxsir
browseable = yes


5.5 关于客户端访问;


5.5.1 Windows 访问;

我们打开Windows的IE浏览器,用IP地址的访问方式就能访问了,格式为 \\192.168.1.3 类似的。当然也可以把共享文件夹挂在本地使用。比如我们把sir01文件夹挂在本地中,应该以sir01用户来挂载,挂载流程图如下;
回复