Chinaunix首页 | 论坛 | 博客
  • 博客访问: 163983
  • 博文数量: 20
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 221
  • 用 户 组: 普通用户
  • 注册时间: 2015-01-14 18:03
个人简介

做好自己份内事

文章分类

全部博文(20)

文章存档

2019年(1)

2018年(2)

2017年(3)

2016年(3)

2015年(11)

我的朋友

分类: LINUX

2015-07-01 14:25:07

samba服务器的概率及用途在此不再累述,本文仅供有基础的工程师遇到文件作为参考。按步骤实现未必能配置正确

一:samba安装命令:


centos、fedora中:
        yum install samba samba-client samba-swat


unbtun:
        apt-get install samba


 二:samba的配置


unbtun中:
        system-config-samba会调出图形界面配置

centos、fedora中:
        此系统中可能无法有图形界面配置,只好修改配置文件了,

修改好配置文件路径/etc/samba/目录下有三个文件;分别是:gdbcommands、smb.conf、smbusers

文件参考内容如下:
gdbcommands:

点击(此处)折叠或打开

  1. bt
  2. quit

smb.conf
:注意文件最后的配置;文件路径以及可以访问用户名,节点名称为显示在windows下文件名称。

点击(此处)折叠或打开

  1. #
  2. # Sample configuration file for the Samba suite for Debian GNU/Linux.
  3. #
  4. #
  5. # This is the main Samba configuration file. You should read the
  6. # smb.conf(5) manual page in order to understand the options listed
  7. # here. Samba has a huge number of configurable options most of which
  8. # are not shown in this example
  9. #
  10. # Some options that are often worth tuning have been included as
  11. # commented-out examples in this file.
  12. # - When such options are commented with ";", the proposed setting
  13. # differs from the default Samba behaviour
  14. # - When commented with "#", the proposed setting is the default
  15. # behaviour of Samba but the option is considered important
  16. # enough to be mentioned here
  17. #
  18. # NOTE: Whenever you modify this file you should run the command
  19. # "testparm" to check that you have not made any basic syntactic
  20. # errors.

  21. #======================= Global Settings =======================

  22. [global]

  23. ## Browsing/Identification ###

  24. # Change this to the workgroup/NT-domain name your Samba server will part of
  25.     workgroup = WORKGROUP

  26. # server string is the equivalent of the NT Description field
  27.     server string = %h server (Samba, Ubuntu)

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

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

  34. # This will prevent nmbd to search for NetBIOS names through DNS.
  35.     dns proxy = no

  36. #### Networking ####

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

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



  47. #### Debugging/Accounting ####

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

  51. # Cap the size of the individual log files (in KiB).
  52.     max log size = 1000

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

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

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


  62. ####### Authentication #######

  63. # Server role. Defines in which mode Samba will operate. Possible
  64. # values are "standalone server", "member server", "classic primary
  65. # domain controller", "classic backup domain controller", "active
  66. # directory domain controller".
  67. #
  68. # Most people will want "standalone sever" or "member server".
  69. # Running as "active directory domain controller" will require first
  70. # running "samba-tool domain provision" to wipe databases and create a
  71. # new domain.
  72.     server role = standalone server

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

  76.     obey pam restrictions = yes

  77. # This boolean parameter controls whether Samba attempts to sync the Unix
  78. # password with the SMB password when the encrypted SMB password in the
  79. # passdb is changed.
  80.     unix password sync = yes

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

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

  90. # This option controls how unsuccessful authentication attempts are mapped
  91. # to anonymous connections
  92.     map to guest = bad user

  93. ########## Domains ###########

  94. #
  95. # The following settings only takes effect if 'server role = primary
  96. # classic domain controller', 'server role = backup domain controller'
  97. # or 'domain logons' is set
  98. #

  99. # It specifies the location of the user's
  100. # profile directory from the client point of view) The following
  101. # required a [profiles] share to be setup on the samba server (see
  102. # below)
  103. ; logon path = \\%N\profiles\%U
  104. # Another common choice is storing the profile in the user's home directory
  105. # (this is Samba's default)
  106. # logon path = \\%N\%U\profile

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

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

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

  121. # This allows machine accounts to be created on the domain controller via the
  122. # SAMR RPC pipe.
  123. # The following assumes a "machines" group exists on the system
  124. ; add machine script = /usr/sbin/useradd -g machines -c "%u machine account" -d /var/lib/samba -s /bin/false %u

  125. # This allows Unix groups to be created on the domain controller via the SAMR
  126. # RPC pipe.
  127. ; add group script = /usr/sbin/addgroup --force-badname %g

  128. ############ Misc ############

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

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

  138. # Setup usershare options to enable non-root users to share folders
  139. # with the net usershare command.

  140. # Maximum number of usershare. 0 (default) means that usershare is disabled.
  141. ;    usershare max shares = 100

  142. # Allow users who've been granted usershare privileges to create
  143. # public shares, not just authenticated ones
  144.     usershare allow guests = yes

  145. #======================= Share Definitions =======================

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

  152. # By default, the home directories are exported read-only. Change the
  153. # next parameter to 'no' if you want to be able to write to them.
  154. ; read only = yes

  155. # File creation mask is set to 0700 for security reasons. If you want to
  156. # create files with group=rw permissions, set next parameter to 0775.
  157. ; create mask = 0700

  158. # Directory creation mask is set to 0700 for security reasons. If you want to
  159. # create dirs. with group=rw permissions, set next parameter to 0775.
  160. ; directory mask = 0700

  161. # By default, \\server\username shares can be connected to by anyone
  162. # with access to the samba server.
  163. # Un-comment the following parameter to make sure that only "username"
  164. # can connect to \\server\username
  165. # This might need tweaking when using external authentication schemes
  166. ; valid users = %S

  167. # Un-comment the following and create the netlogon directory for Domain Logons
  168. # (you need to configure Samba to act as a domain controller too.)
  169. ;[netlogon]
  170. ; comment = Network Logon Service
  171. ; path = /home/samba/netlogon
  172. ; guest ok = yes
  173. ; read only = yes

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

  186. [printers]
  187.     comment = All Printers
  188.     browseable = no
  189.     path = /var/spool/samba
  190.     printable = yes
  191. ;    guest ok = no
  192. ;    read only = yes
  193.     create mask = 0700

  194. # Windows clients look for this share name as a source of downloadable
  195. # printer drivers
  196. [print$]
  197.     comment = Printer Drivers
  198.     path = /var/lib/samba/printers
  199. ;    browseable = yes
  200. ;    read only = yes
  201. ;    guest ok = no
  202. # Uncomment to allow remote administration of Windows print drivers.
  203. # You may need to replace 'lpadmin' with the name of the group your
  204. # admin users are members of.
  205. # Please note that you also need to set appropriate Unix permissions
  206. # to the drivers directory for these users to have write rights in it
  207. ; write list = root, @lpadmin

  208. [code_work]
  209.     comment = work
  210.     path = /home/xiaoxiao/code_work
  211.     writeable = yes
  212. ;    browseable = yes
  213.     valid users = xiaoxiao

smbusers:用户名设置为系统用户名下面,注意修改。(例如你的系统用户名为:X。此文件内容为:X = xiaoxiao。xiaoxiao保持与上个文件中可访问用户名相同)

点击(此处)折叠或打开

  1. xiaoxiao = xiaoxiao

如果有问题参考下面注意事项:
一:修改linux防火墙开关端口


#/etc/init.d/iptables status ##查看防火墙状态


#/etc/init.d/iptable stop ##本次关闭防火墙


#/etc/init.d/iptable restart ##重启防火墙


1、开启端口(以80端口为例)
方法一:
 
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT   写入修改
 
/etc/init.d/iptables save   保存修改
 
service iptables restart    重启防火墙,修改生效
 
方法二:
 
vi /etc/sysconfig/iptables  打开配置文件加入如下语句:
 
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT   重启防火墙,修改完成

2、关闭端口
 
方法一:
 
/sbin/iptables -I INPUT -p tcp --dport 80 -j DROP   写入修改
 
/etc/init.d/iptables save   保存修改
 
service iptables restart    重启防火墙,修改生效
 
方法二:
 
vi /etc/sysconfig/iptables  打开配置文件加入如下语句:
 
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j DROP   重启防火墙,修改完成


3、查看端口状态
 
/etc/init.d/iptables status

二:增加开关机自启动命令:


chkconfig --level 35 smb [service name] off|on

三:linux操作系统中smb服务使用什么端口:


netstat -anpl | grep mbd

四:增加samba账号命令:


smbpasswd -a    系统用户名

五:windows无权限访问路径
上面设置好之后重启samba服务,(/etc/init.d/smb restart)


然后设置selinux:(会导致windows无权限访问路径)


确保setlinux关闭,用:setenforce 0命令执行。 默认的,SELinux禁止网络上对Samba服务器上的共享目录进行写操作,即使你在smb.conf中允许了这项操作。

可以修改配置文件:
vi /etc/selinux/config


修改
SELINUX=enforcing

SELINUX=disabled


阅读(1825) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~