Chinaunix首页 | 论坛 | 博客
  • 博客访问: 37940
  • 博文数量: 14
  • 博客积分: 46
  • 博客等级: 民兵
  • 技术积分: 85
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-02 16:53
文章分类

全部博文(14)

文章存档

2013年(5)

2012年(7)

2011年(2)

我的朋友

分类: LINUX

2013-03-08 08:49:21


# uname -a
Linux localhost.wireless.fc11 2.6.29.4-167.fc11.i686.PAE #1 SMP Wed May 27 17:28:22 EDT 2009 i686 i686 i386 GNU/Linux

# service smb
用法:/etc/init.d/smb {start|stop|restart|reload|status|condrestart}


1、确认samba服务器是否已经启动
    看是否有/etc/init.d/smb文件,没有则需安装

2、将smb服务添加到防火墙的例外中 && 将smb设为开机自动启动服务
    以root用户执行setup命令,弹出配置界面;
    防火墙配置->定制->选中【Samba】;
    系统服务->选中【smb】;
    退出。

3、禁用selinux服务
    编辑selinux的配置文件
    #vim /etc/selinux/config

将SELINUX设置为disabled保存后退出。重启生效,或使用命令
#setenforce 0

  1. # This file controls the state of SELinux on the system.
  2. # SELINUX= can take one of these three values:
  3. # enforcing - SELinux security policy is enforced.
  4. # permissive - SELinux prints warnings instead of enforcing.
  5. # disabled - SELinux is fully disabled.
  6. SELINUX=disabled
  7. # SELINUXTYPE= type of policy in use. Possible values are:
  8. # targeted - Only targeted network daemons are protected.
  9. # strict - Full SELinux protection.
  10. SELINUXTYPE=targeted
4、配置smb的配置文件
    #cp /etc/samba/smb.conf /etc/samba/smb.conf.org; vim /etc/samba/smb.conf    

下面是我自己的配置文件;允许访问IP限制172.16.162.XXX(根据自己需要设定);共享目录/home/share(更改完全读写权限“chmod -R 0777 /home/share”)

  1. # This is the main Samba configuration file. You should read the
  2. # smb.conf(5) manual page in order to understand the options listed
  3. # here. Samba has a huge number of configurable options (perhaps too
  4. # most of which are not shown in this example
  5. #
  6. # For a step to step guide on installing, configuring and using samba,
  7. # read the Samba-HOWTO-Collection. This may be obtained from:
  8. # http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf
  9. #
  10. # Many working examples of smb.conf files can be found in the
  11. # Samba-Guide which is generated daily and can be downloaded from:
  12. # http://www.samba.org/samba/docs/Samba-Guide.pdf
  13. #
  14. # Any line which starts with a ; (semi-colon) or a # (hash)
  15. # is a comment and is ignored. In this example we will use a #
  16. # for commentry and a ; for parts of the config file that you
  17. # may wish to enable
  18. #
  19. # NOTE: Whenever you modify this file you should run the command "testparm"
  20. # to check that you have not made any basic syntactic errors.
  21. #
  22. #---------------
  23. # SELINUX NOTES:
  24. #
  25. # If you want to use the useradd/groupadd family of binaries please run:
  26. # setsebool -P samba_domain_controller on
  27. #
  28. # If you want to share home directories via samba please run:
  29. # setsebool -P samba_enable_home_dirs on
  30. #
  31. # If you create a new directory you want to share you should mark it as
  32. # "samba-share_t" so that selinux will let you write into it.
  33. # Make sure not to do that on system directories as they may already have
  34. # been marked with othe SELinux labels.
  35. #
  36. # Use ls -ldZ /path to see which context a directory has
  37. #
  38. # Set labels only on directories you
  39. # To set a label use the following: chcon -t samba_share_t /path
  40. #
  41. # If you need to share a system created directory you can use one of the
  42. # following (read-only/read-write):
  43. # setsebool -P samba_export_all_ro on
  44. # or
  45. # setsebool -P samba_export_all_rw on
  46. #
  47. # If you want to run scripts (preexec/root prexec/print command/...) please
  48. # put them into the /var/lib/samba/scripts directory so that smbd will be
  49. # allowed to run them.
  50. # Make sure you COPY them and not MOVE them so that the right SELinux context
  51. # is applied, to check all is ok use restorecon -R -v /var/lib/samba/scripts
  52. #
  53. #--------------
  54. #
  55. #======================= Global Settings =====================================

  56. [global]

  57. # ----------------------- Netwrok Related Options -------------------------
  58. #
  59. # workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
  60. #
  61. # server string is the equivalent of the NT Description field
  62. #
  63. # netbios name can be used to specify a server name not tied to the hostname
  64. #
  65. # Interfaces lets you configure Samba to use multiple interfaces
  66. # If you have multiple network interfaces then you can list the ones
  67. # you want to listen on (never omit localhost)
  68. #
  69. # Hosts Allow/Hosts Deny lets you restrict who can connect, and you can
  70. # specifiy it as a per share option as well
  71. #
  72.     workgroup = MYGROUP
  73.     server string = Samba Server Version %v

  74. ;    netbios name = MYSERVER

  75. ;    interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24
  76.     hosts allow = 172.16.162.

  77. # --------------------------- Logging Options -----------------------------
  78. #
  79. # Log File let you specify where to put logs and how to split them up.
  80. #
  81. # Max Log Size let you specify the max size log files should reach

  82.     # logs split per machine
  83.     log file = /var/log/samba/log.%m
  84.     # max 50KB per log file, then rotate
  85.     max log size = 50

  86. # ----------------------- Standalone Server Options ------------------------
  87. #
  88. # Scurity can be set to user, share(deprecated) or server(deprecated)
  89. #
  90. # Backend to store user information in. New installations should
  91. # use either tdbsam or ldapsam. smbpasswd is available for backwards
  92. # compatibility. tdbsam requires no further configuration.

  93. ;    security = domain
  94. ;    passdb backend = tdbsam

  95. # ----------------------- Domain Members Options ------------------------
  96. #
  97. # Security must be set to domain or ads
  98. #
  99. # Use the realm option only with security = ads
  100. # Specifies the Active Directory realm the host is part of
  101. #
  102. # Backend to store user information in. New installations should
  103. # use either tdbsam or ldapsam. smbpasswd is available for backwards
  104. # compatibility. tdbsam requires no further configuration.
  105. #
  106. # Use password server option only with security = server or if you can't
  107. # use the DNS to locate Domain Controllers
  108. # The argument list may include:
  109. # password server = My_PDC_Name [My_BDC_Name] [My_Next_BDC_Name]
  110. # or to auto-locate the domain controller/s
  111. # password server = *


  112. ;    security = domain
  113. ;    passdb backend = tdbsam
  114. ;    realm = MY_REALM

  115. ;    password server =

  116. # ----------------------- Domain Controller Options ------------------------
  117. #
  118. # Security must be set to user for domain controllers
  119. #
  120. # Backend to store user information in. New installations should
  121. # use either tdbsam or ldapsam. smbpasswd is available for backwards
  122. # compatibility. tdbsam requires no further configuration.
  123. #
  124. # Domain Master specifies Samba to be the Domain Master Browser. This
  125. # allows Samba to collate browse lists between subnets. Don't use this
  126. # if you already have a Windows NT domain controller doing this job
  127. #
  128. # Domain Logons let Samba be a domain logon server for Windows workstations.
  129. #
  130. # Logon Scrpit let yuou specify a script to be run at login time on the client
  131. # You need to provide it in a share called NETLOGON
  132. #
  133. # Logon Path let you specify where user profiles are stored (UNC path)
  134. #
  135. # Various scripts can be used on a domain controller or stand-alone
  136. # machine to add or delete corresponding unix accounts
  137. #
  138.     security = user
  139. ;    passdb backend = tdbsam

  140. ;    domain master = yes
  141. ;    domain logons = yes

  142.     # the login script name depends on the machine name
  143. ;    logon script = %m.bat
  144.     # the login script name depends on the unix user used
  145. ;    logon script = %u.bat
  146. ;    logon path = \%LProfiles%u
  147.     # disables profiles support by specifing an empty path
  148. ;    logon path =

  149. ;    add user script = /usr/sbin/useradd "%u" -n -g users
  150. ;    add group script = /usr/sbin/groupadd "%g"
  151. ;    add machine script = /usr/sbin/useradd -n -c "Workstation (%u)" -M -d /nohome -s /bin/false "%u"
  152. ;    delete user script = /usr/sbin/userdel "%u"
  153. ;    delete user from group script = /usr/sbin/userdel "%u" "%g"
  154. ;    delete group script = /usr/sbin/groupdel "%g"


  155. # ----------------------- Browser Control Options ----------------------------
  156. #
  157. # set local master to no if you don't want Samba to become a master
  158. # browser on your network. Otherwise the normal election rules apply
  159. #
  160. # OS Level determines the precedence of this server in master browser
  161. # elections. The default value should be reasonable
  162. #
  163. # Preferred Master causes Samba to force a local browser election on startup
  164. # and gives it a slightly higher chance of winning the election
  165. ;    local master = no
  166. ;    os level = 33
  167. ;    preferred master = yes

  168. #----------------------------- Name Resolution -------------------------------
  169. # Windows Internet Name Serving Support Section:
  170. # Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
  171. #
  172. # - WINS Support: Tells the NMBD component of Samba to enable it's WINS Server
  173. #
  174. # - WINS Server: Tells the NMBD components of Samba to be a WINS Client
  175. #
  176. # - WINS Proxy: Tells Samba to answer name resolution queries on
  177. # behalf of a non WINS capable client, for this to work there must be
  178. # at least one    WINS Server on the network. The default is NO.
  179. #
  180. # DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names
  181. # via DNS nslookups.

  182. ;    wins support = yes
  183. ;    wins server = w.x.y.z
  184. ;    wins proxy = yes

  185. ;    dns proxy = yes

  186.     username map = /etc/samba/smbusers

  187. # --------------------------- Printing Options -----------------------------
  188. #
  189. # Load Printers let you load automatically the list of printers rather
  190. # than setting them up individually
  191. #
  192. # Cups Options let you pass the cups libs custom options, setting it to raw
  193. # for example will let you use drivers on your Windows clients
  194. #
  195. # Printcap Name let you specify an alternative printcap file
  196. #
  197. # You can choose a non default printing system using the Printing option

  198. ;    load printers = yes
  199.     cups options = raw

  200. ;    printcap name = /etc/printcap
  201.     #obtain list of printers automatically on SystemV
  202. ;    printcap name = lpstat
  203. ;    printing = cups

  204. # --------------------------- Filesystem Options ---------------------------
  205. #
  206. # The following options can be uncommented if the filesystem supports
  207. # Extended Attributes and they are enabled (usually by the mount option
  208. # user_xattr). Thess options will let the admin store the DOS attributes
  209. # in an EA and make samba not mess with the permission bits.
  210. #
  211. # Note: these options can also be set just per share, setting them in global
  212. # makes them the default for all shares

  213. ;    map archive = no
  214. ;    map hidden = no
  215. ;    map read only = no
  216. ;    map system = no
  217. ;    store dos attributes = yes


  218. #============================ Share Definitions ==============================

  219. [homes]
  220.     comment = Home Directories
  221.     browseable = no
  222.     writable = yes
  223. ;    valid users = %S
  224. ;    valid users = MYDOMAIN%S

  225. [printers]
  226.     comment = All Printers
  227.     path = /var/spool/samba
  228.     browseable = no
  229. ;    guest ok = no
  230. ;    writable = No
  231.     printable = yes

  232. # A publicly accessible directory, but read only, except for people in
  233. # the "staff" group
  234. ;    [public]
  235. ;    comment = Public Stuff
  236. ;    path = /home/samba
  237. ;    public = yes
  238. ;    writable = yes
  239. ;    printable = no
  240. ;    write list = +staff

  241. [share]
  242.     comment = share directory
  243.     path = /home/share
  244.     guest ok = yes
  245. ;    browseable = yes
  246.     writeable = yes
  247.     create mask = 0765

 

5、添加可访问smb共享服务的用户
    #smbpasswd -a username
    设置密码
    确认密码

    使用这种方法添加的用户,必须首先是系统里存在的用户。
    添加系统用户的方法:
    #useradd xxxx -p xxxx

6、重新启动smb服务
    #/etc/init.d/smb restart
    or
    #service smb restart

到此为止,samba配置完毕,在windows下即可用 的方式访问linux的共享了

如发现无法访问,可在/etc/samba/smbusers文件中增加访问用户,下面增加了wireless用户。
#vim /etc/samba/smbusers 

  1. # Unix_name = SMB_name1 SMB_name2 ...
  2. root = administrator admin
  3. nobody = guest pcguest smbguest
  4. wireless = wireless

参考:http://blog.csdn.net/binglingshuang/article/details/3376541
阅读(1427) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~