当前位置:   article > 正文

【验】Samba安装测试详解_smbd测试免费

smbd测试免费

Samba安装测试详解

 

samba-client.i386

samba-common.i386

samba.i386

samba-swat.i386

 

1、安装软件包

# yum install samba* -y

2、添加组

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

groupadd develop

3、添加用户到组

  1. #添加test用户到组develop
  2. useradd -g develop -s /sbin/nologin test

4、添加samba用户和设置密码

smbpasswd命令的常用方法

smbpasswd -a 增加用户(要增加的用户必须以是系统用户)
smbpasswd -d 冻结用户,就是这个用户不能在登录了
smbpasswd -e 恢复用户,解冻用户,让冻结的用户可以在使用
smbpasswd -n 把用户的密码设置成空.
             要在global中写入 null passwords -true
smbpasswd -x  删除用户

smbpasswd -a test

 

5、配置目录 /etc/samba

 

man smb.conf

 

# vim /etc/samba/smb.conf

[stable]
   comment = stable
   browseable = no
   public = no
   path = /diskb/stable
   guest ok = no
   create mask = 0776
   directory mask = 0777
   read only = no
   valid users = @st, @develop
   write list = @st


[global]

        workgroup = MYGROUP

        server string = Samba Server Version %v

        security = user

        passdb backend = tdbsam

        load printers = yes

        cups options = raw

 

 

[homes]

        comment = Home Directories

        browseable = no

        writable = yes

[printers]

        comment = All Printers

        path = /var/spool/samba

        browseable = no

        guest ok = no   # <--- yes匿名可以访问,no拒绝匿名访问

        writable = no   # <--- yes 资源可以写,no只读

        printable = yes

 

 

[share]

comment = This is rhce testing

path = /common

browseable = yes #<---让资源可见

hosts allow = .example.com  # <---只允许example.com域下的用户访问

valid users = user1  # <---该资源只对user1用户有效,别的用户不能访问

writable = yes  # <--资源可写

 

 

2、创建目录并且修改selinux上下文

 

# mkdir /common

# chmod 775 /common

 

 

# chcon -R -t samba_share_t /common

# setsebool -P samba_export_all_ro on

或者

# setsebool -P samba_export_all_rw on

 

 

3、创建samba独立的帐号

注意:这些帐号必须是系统上本身就拥有的帐号

 

[  useradd user1  ]

 

 

# smbpasswd --help

 

 

# smbpasswd  -a user1 <---添加user1到smb专用的帐号数据文件里

 

4、设定iptables

samber有两个进程:

nmbd 137 , 138

smbd 139 , 445

 

 

iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A INPUT -i lo -j ACCEPT

iptables -A INPUT -p tcp -m multiport --dports 137,138,139,445 -j ACCEPT

iptables -A INPUT -p udp -m multiport --dports 137,138,139,445 -j ACCEPT

5、测试

# service smb restart

 

 

# smbclient -L //192.168.0.249 -U user1  <--列出可以访问的资源

# smbclient //192.168.0.249/share -U user1 <--访问名字叫share的资源

 

如果共享的目录是公共的目录,也就是该目录也被别的服务共享,selinux上下文这样设定:

# chcon -t public_content_t /common

# chcon -t public_content_rw_t /common/pub

 

总结:

如果/common目录被nfs,vsftp,samba同时共享出去

selinux设定:

如果要求对该目录有写的权限:

chcon -R -t public_content_rw_t /common

如果是只读:

chcon -R -t public_content_t /common

 

 

文件系统权限:

如果要求对该目录有写的权限:

chmod 775 /common

chown root:XXXX /common   《--XXXX代表通过samba在该目录写文件的哟用户所在的组

 

iptables设定(samba,nfs,ftp):

 

modprobe ip_conntrack_ftp  <---非常重要

echo "modprobe ip_conntrack_ftp"  >> /erc/rc.d/rc.local

 

 

 

iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A INPUT -i lo -j ACCEPT

iptables -A INPUT -p tcp -m multiport --dports 20,21,137,138,139,445,875,32803,32769,892,662,2020,111,2049 -j ACCEPT

 

 

iptables -P INPUT DROP

 

 

练习:

 

 

1、通过samba共享/common目录,要求不允许t113.org域的所有用户访问。只允许user2访问该资源

 

[share]

comment = "test"

path = /common

hosts deny = .t113.org

valid users = user2

 

useradd user2

smbpasswd -a user2

 

2、分别通过smbclient访问用户的家目录资源,测试是否支持上传等操作

给我找到和samba家目录有关的selinux布尔值设定

getsebool 命令 找到

# getsebool  -a | grep samba

samba_domain_controller --> off

samba_enable_home_dirs --> off  《-----

samba_export_all_ro --> off

samba_export_all_rw --> on

samba_share_nfs --> off

use_samba_home_dirs --> off  《-----

virt_use_samba --> off

 

 

setsebool -P samba_enable_home_dirs=1

setsebool -P use_samba_home_dirs=1

 

3、通过samba共享/share目录,要求所有人都可以访问,而且匿名也可以访问,并且匿名也可以上传文件。

 

 

[pub]

comment = "Public source"

path = /share

guest ok = yes

browseable = yes

writable = yes

 

 

# chcon -t public_content_rw_t /share/

 

 

还需设定目录权限和selinux策略

chmod 777 /share

setsebool -P allow_smbd_anon_write=1

 

 

测试

# smbclient -L //192.168.0.249

# smbclient  //192.168.0.249

 

  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. [stable]
  209. comment = stable
  210. browseable = yes
  211. path = /diskb/stable
  212. guest ok = no
  213. create mask = 0776
  214. directory mask = 0776
  215. read only = no
  216. valid users = @stable
  217. write list = @stable
  218. [develop]
  219. comment = develop
  220. browseable = yes
  221. path = /diskb/develop
  222. guest ok = no
  223. create mask = 0776
  224. directory mask = 0776
  225. read only = no
  226. valid users = @sr
  227. write list = @sr
  228. [person]
  229. comment = person
  230. browseable = no
  231. path = /diskb/person
  232. guest ok = no
  233. create mask = 0776
  234. directory mask = 0776
  235. read only = no
  236. valid users = sr
  237. write list = sr
  238. [normal]
  239. comment = normal
  240. browseable = yes
  241. path = /diskb/normal
  242. guest ok = yes
  243. create mask = 0777
  244. directory mask = 0777
  245. read only = no

共享参数

================== Share Definitions ==================
[共享名]

comment = 任意字符串
说明:comment是对该共享的描述,可以是任意字符串。

path = 共享目录路径
说明:path用来指定共享目录的路径。可以用%u、%m这样的宏来代替路径里的unix用户和客户机的Netbios名,用宏表示主要用于[homes]共享域。例如:如果我们不打算用home段做为客户的共享,而是在/home/share/下为每个Linux用户以他的用户名建个目录,作为他的共享目录,这样path就可以写成:path = /home/share/%u; 。用户在连接到这共享时具体的路径会被他的用户名代替,要注意这个用户名路径一定要存在,否则,客户机在访问时会找不到网络路径。同样,如果我们不是以用户来划分目录,而是以客户机来划分目录,为网络上每台可以访问samba的机器都各自建个以它的netbios名的路径,作为不同机器的共享资源,就可以这样写:path = /home/share/%m 。

browseable = yes/no
说明:browseable用来指定该共享是否可以浏览。

writable = yes/no
说明:writable用来指定该共享路径是否可写。

available = yes/no
说明:available用来指定该共享资源是否可用。

admin users = 该共享的管理者
说明:admin users用来指定该共享的管理员(对该共享具有完全控制权限)。在samba 3.0中,如果用户验证方式设置成“security=share”时,此项无效。
例如:admin users =bobyuan,jane(多个用户中间用逗号隔开)。

valid users = 允许访问该共享的用户
说明:valid users用来指定允许访问该共享资源的用户。
例如:valid users = bobyuan,@bob,@tech(多个用户或者组中间用逗号隔开,如果要加入一个组就用“@+组名”表示。)

invalid users = 禁止访问该共享的用户
说明:invalid users用来指定不允许访问该共享资源的用户。
例如:invalid users = root,@bob(多个用户或者组中间用逗号隔开。)

write list = 允许写入该共享的用户
说明:write list用来指定可以在该共享下写入文件的用户。
例如:write list = bobyuan,@bob

public = yes/no
说明:public用来指定该共享是否允许guest账户访问。

guest ok = yes/no
说明:意义同“public”。

转自:http://www.2cto.com/os/201310/249248.html

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/182472
推荐阅读
相关标签
  

闽ICP备14008679号