Linux CentOS 7 - Samba server and client
Share a directory via samba so that all users/clients within the example.com domain can read its content; user smbuser1 must have read accessOn system1
Install and activate Samba on Server:
# yum install samba samba-common-tools –y
# systemctl enable smb nmb
# systemctl start smb nmb
Firewall rule for Samba:
# firewall-cmd –permanent –add-service=samba
# firewall-cmd –reload
Create the directory
# mkdir /samba-share
# chmod 777 /samba-share
Create Samba User:
# useradd smbuser1 –s /sbin/nologin
# smbpasswd –a smbuser1
Enable Samba user
# smppasswd -e smbuser1 enable user
Test user database
# pdbedit –L
Create your share on the configuration file
# vim /etc/samba/smb.conf
You can allow a specific host in the Global Options if required;
[samba]
comment = samba share
path = /samba-share
browseable = yes
writable = no
valid users = smbuser1
hosts
allow = 192.168.189.0/24
# systemctl restart smb nmb
Check the configuration
# testparm
Browse the Samba Share on the Server:
# smbclient –L 192.168.189.140 –U smbuser1
Install package for semanage command
#yum install policycoreutils-devel -y
Adjust Selinux context
# semanage fcontext –a –t samba_share_t “/samba-share(/.*)?”
# restorecon –Rv /samba-share
Adjust Selinux Boolean settings
# setsebool –P samba_export_all_ro on ## if you need it read only.
# setsebool –P samba_export_all_rw on ## if you need it read and write.
Verify that you can create files in the shared directory:
# cd /samba-share
# touch 123.txt
# ls -> 123.txt
On system2
On the Samba Client:Install the packages:
# yum install cifs-utils* samba-client* –y
Add firewall rule:
# firewall-cmd –permanent –add-service=samba-client
# firewall-cmd –reload
Create a mount point for the Samba share
# mkdir /mnt/samba-share
Mount the samba share:
# mount –t cifs //192.168.189.140/samba /mnt/samba-share –o username=smbuser1
We can mount it permanently on the /etc/fstab file:
//192.168.189.140/samba /mnt/samba-share cifs username=smbuser1,password=admin 0 0
Verify that the created file can be read:
# cd /mnt/samba-share
# ls ## should show 123.txt
# touch 456 ## should return an error as the directory is read only
# su – smbuser1
$ cifscreds add system1 ## make sure system1 can be resolved by DNS
(input password for user smbuser1)
Then smbuser1 can read/write on the /mnt directory
$ exit
In order for system1 to be resolved to its IP address, it has to be included in the /etc/hosts file.
If you experience any problem with this configuration, please let me know.
Commenti
Posta un commento