【验】Samba安装测试详解

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、添加用户到组

#添加test用户到组develop

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

 

#                                                                                                                      
# 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                                                                                        
#                                                                                                                      
# Some options that are often worth tuning have been included as                                                       
# commented-out examples in this file.                                                                                 
#  - When such options are commented with ";", the proposed setting                                                    
#    differs from the default Samba behaviour                                                                          
#  - When commented with "#", the proposed setting is the default                                                      
#    behaviour of Samba but the option is considered important                                                         
#    enough to be mentioned here                                                                                       
#                                                                                                                      
# 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                                                                                               
                                                                                                                       
# server string is the equivalent of the NT Description field                                                          
        server string = %h server (Samba, 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.                                                      
   dns proxy = no                                                                                                      
                                                                                                                       
#### 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 = yes                                                                                         
                                                                                                                       
                                                                                                                       
                                                                                                                       
#### Debugging/Accounting ####                                                                                         
                                                                                                                       
# This tells Samba to use a separate log file for each machine                                                         
# that connects                                                                                                        
   log file = /var/log/samba/log.%m                                                                                    
                                                                                                                       
# Cap the size of the individual log files (in KiB).                                                                   
   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 #######                                                                                         
                                                                                                                       
# Server role. Defines in which mode Samba will operate. Possible                                                      
# values are "standalone server", "member server", "classic primary                                                    
# domain controller", "classic backup domain controller", "active                                                      
# directory domain controller".                                                                                        
#                                                                                                                      
# Most people will want "standalone sever" or "member server".                                                         
# Running as "active directory domain controller" will require first                                                   
# running "samba-tool domain provision" to wipe databases and create a                                                 
# new domain.                                                                                                          
   server role = standalone server                                                                                     
                                                                                                                       
# 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                                                                                         
                                                                                                                       
# 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 = yes                                                                                            
                                                                                                                       
# 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 chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\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 = yes                                                                                           
                                                                                                                       
# This option controls how unsuccessful authentication attempts are mapped                                             
# to anonymous connections                                                                                             
   map to guest = bad user                                                                                             
                                                                                                                       
########## Domains ###########                                                                                         
                                                                                                                       
#                                                                                                                      
# The following settings only takes effect if 'server role = primary                                                   
# classic domain controller', 'server role = backup domain controller'                                                 
# or '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                                            
# (this is Samba's default)                                                                                            
#   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                                        
                                                                                                                       
# This allows machine accounts to be created on the domain controller via the                                          
# SAMR RPC pipe.                                                                                                       
# The following assumes a "machines" group exists on the system                                                        
; add machine script  = /usr/sbin/useradd -g machines -c "%u machine account" -d /var/lib/samba -s /bin/false %u       
                                                                                                                       
# This allows Unix groups to be created on the domain controller via the SAMR                                          
# RPC pipe.                                                                                                            
; add group script = /usr/sbin/addgroup --force-badname %g                                                             
                                                                                                                       
############ 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                                                                              
                                                                                                                       
# 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                                                                                         
                                                                                                                       
# Setup usershare options to enable non-root users to share folders                                                    
# with the net usershare command.                                                                                      
                                                                                                                       
# Maximum number of usershare. 0 (default) means that usershare is disabled.                                           
;   usershare max shares = 100                                                                                         
                                                                                                                       
# Allow users who've been granted usershare privileges to create                                                       
# public shares, not just authenticated ones                                                                           
   usershare allow guests = yes                                                                                        
                                                                                                                       
#======================= 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, the home directories are exported read-only. Change the                                                  
# next parameter to 'no' if you want to be able to write to them.                                                      
;   read only = yes                                                                                                    
                                                                                                                       
# File creation mask is set to 0700 for security reasons. If you want to                                               
# create files with group=rw permissions, set next parameter to 0775.                                                  
;   create mask = 0700                                                                                                 
                                                                                                                       
# 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                                                                                              
                                                                                                                       
# 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                                                                                     
# This might need tweaking when using external authentication schemes                                                  
;   valid users = %S                                                                                                   
                                                                                                                       
# 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                                                                                                     
;   read only = yes                                                                                                    
                                                                                                                       
# 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                                                                                              
                                                                                                                       
[printers]                                                                                                             
   comment = All Printers                                                                                              
   browseable = no                                                                                                     
   path = /var/spool/samba                                                                                             
   printable = yes                                                                                                     
   guest ok = no                                                                                                       
   read only = yes                                                                                                     
   create mask = 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.                                                   
# You may need to replace 'lpadmin' with the name of the group your                                                    
# admin users are members of.                                                                                          
# Please note that you also need to set appropriate Unix permissions                                                   
# to the drivers directory for these users to have write rights in it                                                  
;   write list = root, @lpadmin                                                                                        
                                                                                                                       
[stable]                                                                                                               
   comment = stable                                                                                                    
   browseable = yes                                                                                                                                                                                                          
   path = /diskb/stable                                                                                                
   guest ok = no                                                                                                       
   create mask = 0776                                                                                                  
   directory mask = 0776                                                                                               
   read only = no                                                                                                      
   valid users = @stable                                                                                               
   write list = @stable                                                                                                
                                                                                                                       
[develop]                                                                                                              
   comment = develop                                                                                                   
   browseable = yes                                                                                                                                                                                                         
   path = /diskb/develop                                                                                               
   guest ok = no                                                                                                       
   create mask = 0776                                                                                                  
   directory mask = 0776                                                                                               
   read only = no                                                                                                      
   valid users = @sr                                                                                                   
   write list = @sr                                                                                                    
                                                                                                                       
[person]                                                                                                               
   comment = person                                                                                                    
   browseable = no                                                                                                                                                                                                          
   path = /diskb/person                                                                                                
   guest ok = no                                                                                                       
   create mask = 0776                                                                                                  
   directory mask = 0776                                                                                               
   read only = no                                                                                                      
   valid users = sr                                                                                                    
   write list = sr                                                                                                     
                                                                                                                       
[normal]                                                                                                               
   comment = normal                                                                                                    
   browseable = yes                                                                                                                                                                                                          
   path = /diskb/normal                                                                                                
   guest ok = yes                                                                                                      
   create mask = 0777                                                                                                  
   directory mask = 0777                                                                                               
   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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值