Configure samba in CentOS 7 [automatic mounting and multi-user mounting]
[Root @ server0 ~] # Yum-y install samba-client
Loaded plugins: langpacks, product-id, submodules-manager
This system is not registered to Red Hat sub‑management. You can use sub‑manager to register.
Resolving Dependencies
--> Running transaction check
..................................... Omit several rows .....................................
Installed:
Samba. x86_64 4. 1.1-31. el7 samba-client.x86_64. 1.1-31. el7
Dependency Installed:
Cups-libs.x86_64. 6.3-14. el7 libldb. x86_64. 1.16-4. el7 libsmbclient. x86_64 4. 1.1-31. el7 libtalloc. x86_64 2. 0.8-4. el7
Libtdb. x86_64. 2.12-3. el7 libtevent. x86_64. 9.18-6. el7 libwbclient. x86_64 4. 1.1-31. el7 pytalloc. x86_64. 0.8-4. el7.
Samba-common.x86_64 0: 4. 1.1-31. el7 samba-libs.x86_64 0: 4. 1.1-31. el7
Complete!
# Start startup
[Root @ server0 ~] # Systemctl enable smb nmb
Ln-s '/usr/lib/systemd/system/smb. service'/etc/systemd/system/multi-user.target.wants/smb. Service'
Ln-s '/usr/lib/systemd/system/nmb. service'/etc/systemd/system/multi-user.target.wants/nmb. Service'
# Start the service
[Root @ server0 ~] # Systemctl start smb nmb
# View the listening port
[Root @ server0 ~] # Ss-tnl
State Recv-Q Send-Q Local Address: Port Peer Address: Port
LISTEN 0 100 127.0.0.1: 25 *:*
LISTEN 0 50 *: 445 *:*
LISTEN 0 50 *: 139 *:*
LISTEN 0 128 *: 22 *:*
LISTEN 0 100: 1: 25 :::*
LISTEN 0 50: 445 :::*
LISTEN 0 50: 139 :::*
LISTEN 0 128: 22 :::*
# Firewall access
[Root @ server0 ~] # Firewall-cmd -- permanent -- add-service = samba
Success
[Root @ server0 ~] # Firewall-cmd -- reload
Success
[Root @ server0 ~] # Mkdir/smb
[Root @ server0 ~] # Vi/etc/samba/smb. conf
..................................... Omit several rows .....................................
[Smb]
Comment = Demo
Path =/smb
Public = yes
Writable = yes
Printable = no
Write list = + qiu
[Root @ server0 ~] # Systemctl restart smb nmb
# Use semanage to modify security context
[Root @ server0 ~] # Yum-y install policycoreutils-python // semanage Tool
Loaded plugins: langpacks, product-id, submodules-manager
This system is not registered to Red Hat sub‑management. You can use sub‑manager to register.
Resolving Dependencies
--> Running transaction check
---> Package policycoreutils-python.x86_64. 2.5-11. el7 will be installed
--> Processing Dependency: audit-libs-python> = 2.1.3-4 for package: policycoreutils-python-2.2.5-11.el7.x86_64
--> Processing Dependency: libsemanage-python> = 2.1.10-1 for package: policycoreutils-python-2.2.5-11.el7.x86_64
--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.2.5-11.el7.x86_64
--> Processing Dependency: libapol. so.4 (VERS_4.0) (64bit) for package: policycoreutils-python-2.2.5-11.el7.x86_64
--> Processing Dependency: libcgroup for package: policycoreutils-python-2.2.5-11.el7.x86_64
..................................... Omit several rows .....................................
Installed:
Policycoreutils-python.x86_64. 2.5-11. el7
Dependency Installed:
Audit-libs-python.x86_64. 3.3-4. el7 checkpolicy. x86_64 2. 1.12-6. el7 libcgroup. x86_64. 41-6.el7
Libsemanage-python.x86_64. 1.10-16. el7 python-IPy.noarch. 75-6.el7 setools-libs.x86_64. 3.7-46. el7
Complete!
[Root @ server0 ~] # Ls-dZ/smb/
Drwxr-xr-x. root unconfined_u: object_r: default_t: s0/smb/
[Root @ server0 ~] # Semanage fcontext-a-t samba_0000_t '/smb (/.*)? '
[Root @ server0 ~] #Restorecon-RFvv/smb/
Restorecon reset/smb context unconfined_u: object_r: default_t: s0-> system_u: object_r: samba_share_t: s0
[Root @ server0 ~] # Chmod 777-R/smb/
# Add an account
[Root @ server0 ~] #Useradd qiu
[Root @ server0 ~] #Smbpasswd-a qiu
New SMB password:
Retype new SMB password:
Added user qiu.
# Client Test
[Root @ server0 ~] #Smbclient // localhost/smb-U [-- user] = qiu
Enter qiu's password:
Domain = [MYGROUP] OS = [Unix] Server = [Samba 4.1.1]
Smb: \> ls
. D 0 Thu Mar 5 08:17:13 2015
.. D 0 Thu Mar 5 08:17:13 2015
46041 blocks of size 524288. 43379 blocks available
Smb: \> mkdir test
Smb: \>Ls
. D 0 Thu Mar 5 08:39:25 2015
.. D 0 Thu Mar 5 08:17:13 2015
Test D 0 Thu Mar 5 08:39:25 2015
46041 blocks of size 524288. 43379 blocks available
# Mount mounting. Because SAMBA belongs to the CIFS type, you need to install the cifs package before mounting.
[Root @ server0 ~] # Yum-y install cifs-utils
Loaded plugins: langpacks, product-id, submodules-manager
This system is not registered to Red Hat sub‑management. You can use sub‑manager to register.
Resolving Dependencies
--> Running transaction check
---> Package cifs-utils.x86_64 0: 6. 2-6.el7 will be installed
--> Processing Dependency: keyutils for package: cifs-utils-6.2-6.el7.x86_64
--> Running transaction check
---> Package keyutils. x86_64. 5.8-3. el7 will be installed
..................................... Omit several rows .....................................
Installed:
Cifs-utils.x86_64 0: 6. 2-6.el7
Dependency Installed:
Keyutils. x86_64. 5.8-3. el7
Complete!
[Root @ server0 ~] #Cat/root/cifs. mount
Username = qiu
Password = 123456
# Domain = xxxxx
[Root @ server0 ~] # Vi/etc/fstab
..................................... Omit several rows .....................................
// Localhost/smb/mnt/smb cifs ults, credentials =/root/cifs. mount 0 0 # You can also write all commands: // localhost/smb/mnt/smb cifs defaults, username = qiu, password = 123456, sec = ntlm 0 0
[Root @ server0 ~] # Mount-
[Root @ server0 ~] # Mount
..................................... Omit several rows .....................................
// Localhost/smb on/mnt/smb type cifs (rw, relatime, vers = 1.0, cache = strict, username = qiu, domain = SERVER0, uid = 0, noforceuid, gid = 0, noforcegid, addr = 0000: 0000: 0000: 0000: 0000: 0000: 0000: 0001, unix, posixpaths, serverino, acl, rsize = 1048576, wsize = 65536, actimeo = 1)
# Multi-user mounting
[Root @ server0 ~] # Vi/etc/samba/smb. conf
..................................... Omit several rows .....................................
[Public]
Comment = Public
Path =/pulibc
Public = yes
Writable = yes
Printable = no
Valid = qiu, min, @ HR
[Root @ server0 ~] # Cat/root/cifs. mount
Username = min
Password = 123456
[Root @ server0 ~] # Vi/etc/fstab
..................................... Omit several rows .....................................
// Localhost/smb/mnt/smb cifs ults, credentials =/root/cifs. mount, multiuser, sec = ntlmssp 0 0
[Root @ server0 ~] # Mount
..................................... Omit several rows .....................................
// Localhost/public on/mnt/public type cifs (rw, relatime, vers = 1.0, sec = ntlmssp, cache = strict, multiuser, domain = SERVER0, uid = 0, noforceuid, gid = 0, noforcegid, addr = 0000: 0000: 0000: 0000: 0000: 0000: 0000, unix, posixpaths, serverino, acl, noperm, rsize = 0001, wsize = 65536, actimeo = 1)
------------------------------------------------ Appendix -----------------------------------------------------
# In this example, the security context is implemented through semanage. Of course, the smb. conf file also contains the configuration in SELINUX. For more information, see.
# This is the main Samba configuration file. For detailed information about
# Options listed here, refer to the smb. conf (5) manual page. Samba has a huge
# Number of optional able options, most of which are not shown in this example.
#
# The Official Samba 3.2.x HOWTO and Reference Guide contains step-by-step
# Guides for installing, logging ing, and using Samba:
# Http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf
#
# The Samba-3 by Example guide has working examples for smb. conf. This guide is
# Generated daily: http://www.samba.org/samba/docs/Samba-Guide.pdf
#
# In this file, lines starting with a semicolon (;) or a hash (#) are
# Comments and are ignored. This file uses hashes to denote commentary and
# Semicolons for parts of the file you may wish to configure.
#
# Note: Run the "testparm" command after modifying this file to check for basic
# Syntax errors.
#
#---------------
# Security-Enhanced Linux (SELinux) Notes:
#
# Turn the samba_domain_controller Boolean on to allow Samba to use the useradd
# And groupadd family of binaries. Run the following command as the root user
# Turn this Boolean on:
# Setsebool-P samba_domain_controller on
#
# Turn the samba_enable_home_dirs Boolean on if you want to share home
# Directories via Samba. Run the following command as the root user to turn this
# Boolean on:
# Setsebool-P samba_enable_home_dirs on
#
# If you create a new directory, such as a new top-level directory, label it
# With samba_assist_t so that SELinux allows Samba to read and write to it. Do
# Not label system directories, such as/etc/and/home/, with samba_share_t,
# Such directories shoshould already have an SELinux label.
#
# Run the "ls-ldZ/path/to/directory" command to view the current SELinux
# Label for a given directory.
#
# Set SELinux labels only on files and directories you have created. Use
# Chcon command to temporarily change a label:
# Chcon-t samba_t _t/path/to/directory
#
# Changes made via chcon are lost when the file system is relabeled or commands
# Such as restorecon are run.
#
# Use the samba_export_all_ro or samba_export_all_rw Boolean to share system
# Directories. To share such directories and only allow read-only permissions:
# Setsebool-P samba_export_all_ro on
# To share such directories and allow read and write permissions:
# Setsebool-P samba_export_all_rw on