First, the demand
- There are several users in the LAN, all users access a shared directory
- Each user has his or her own folder in the shared directory.
- Each user can read other people's folders
- Each user can have write access to their own folders only
- All users belong to the Filesgroup group
Second, the environment
Server: CENTOS6
Host Name: Fileserver
IP Address: 192.168.1.2
Client IP network segment: 192.168.1.0/24, 192.168.2.0/24, 172.16.1.0/24
Third, the configuration steps
1. Install Samba, back up the original configuration file, edit the configuration file
[Email protected] ~]#Yum InstallSamba Samba-common samba-Client[[email protected] ~]# Cp/etc/samba/smb.conf/root[[email protected]~]#VI/etc/samba/smb.conf
The following shows the edited content #======================= Global Settings =====================================[global]#-----------------------Network related Options-------------------------Workgroup=FILEGROUPNetBIOS Name=Fileserver Interfaces= Lo eth0192.168.1.2/the network card and IP address of the Samba service monitorhosts allow=127.192.168.1.192.168.2.172.16.1. # Allow access to IP segment: Server native, 192.168.1.x, 192.168.2.x, 172.16.1.x#---------------------------Logging Options-----------------------------Logfile=/var/log/samba/log.%m #默认不变 max log size=#默认不变# -----------------------Standalone Server Options------------------------Security=User # Standalone authentication passdb backend=SMBPASSWD # Saving users and Passwords with /var/lib/samba/private/smbpasswd text Files #============================ Share Definitions ==============================# There are many default profile settings commented out, and finally added custom settings #[homes]; Comment=Home directories; Browseable=No; Writable=Yes; Valid Users= %S; Valid Users= mydomain\%S #[printers]; Comment=All Printers; Path=/var/spool/Samba; Browseable=No; Guest OK=No; Writable=No; Printable=Yes # Un-comment the following and create the Netlogon directory forDomain logons; [Netlogon]; Comment=Network Logon Service; Path=/var/lib/samba/Netlogon; Guest OK=Yes; Writable=No; Share Modes=No # Un-comment The following to provide a specific roving profiles share# The default is to use the user'S home Directory; [Profiles]; Path=/var/lib/samba/profiles; Browseable=No; Guest OK=Yes # A publicly accessible directory, but read only, except forPeopleinch# the" Staff"Group; [Public]; Comment=Public Stuff; Path=/home/Samba; Public=Yes; Writable=Yes; Printable=No; WriteList = +staff# customizing file sharing settings [files] Comment=Files Path=/opt/Files Public=No writable=Yes printable=NoWriteList = @filesgroup
2. Add groups, create shared folders, set SELinux
[Email protected] ~mkdir /opt/~]# chcon-t samba_share_t/opt/files
3. Set Samba to boot and start Samba
[[Email protected] ~]# chkconfig SMB on[[email protected] ~]# service SMB start
4. Add Users in bulk
Echo passwd mkdir Chown Echo " %p\n%p " | Smbpasswd-a-S%u
Instruction Explanation:
- This line instruction consists of multiple directives, with the && connection between instructions, that is, the last instruction executes successfully before the next
- %u on behalf of user name,%p for password,%d for user folder
- A small number of users can edit the batch instruction in the text editor, each paste a line, with the Find and replace function to replace%u for the user name,%p password,%d for the user directory
- A large number of users are recommended to write a user name, password, folder name to the file, script read file automatically executed
EXPLANATION BY clause:
useradd-mn%u-s/sbin/nologin Add user,-mn indicates that the user home directory and user base group are not created,-s/sbin/nologin indicates that the user is not logged on Server echo %p | passwd --stdin%u set the password for the user (can be omitted) usermod -ag filesgroup%mk Dir -p/opt/files/%d create user folder in shared directory c Hown -R%u:/opt/files/%d User folder owner to user's own echo -E %p\n%p " | Smbpasswd-a-S%u add Samba user account, smbpasswd-a-s%u is silently add samba account, echo-e "%p\n%p" is two times output password%p, intermediate output return \ n
5, set the shared directory belongs to the group, set the GUID for the shared directory, so that all user-created files belong to the Filesgroup group, prevent users outside the Filesgroup group from reading, executing
[Email protected] ~]# chown-r: filesgroup/opt/fils
[Email protected] ~]# chmod-r g+s/opt/files
[Email protected] ~]# chmod-r o-rx/opt/files/
[Email protected] ~]#
6. Take a look at the generated directory
[email protected] ~]# ls-ldz/opt/files
drwxr-s---. root filesgroup unconfined_u:object_r:samba_share_t:s0/opt/files
[email protected] ~]#
[email protected] ~]# ls-lz/opt/files
drwxr-s---. user1 filesgroup unconfined_u:object_r:samba_share_t:s0 dir1
drwxr-s---. user2 filesgroup unconfined_u:object_r:samba_share_t:s0 dir2
drwxr-s---. user3 filesgroup unconfined_u:object_r:samba_share_t:s0 dir3
[email protected] ~]#
[email protected] ~]# ll/var/lib/samba/private/smbpasswd
-rw-------. 1 root root 1435 2015-04-13 16:59/var/lib/samba/private/smbpasswd
[email protected] ~]#
Thanks:http://www.cnblogs.com/mchina/archive/2012/12/18/2816717.html
CENTOS6 configuring Samba servers and adding users and folders in bulk