Task: Samba
You are required to share /share_data with samba in server1. The service should be accessible to 192.168.122.0/24 subnet only. In desktop1 share mount the share in /smbshare folder permanently. Only user shiba and users in sales group should be able to access the share and only shiba should be able to write to the share. Share name should be myshare and set workgroup to myworkgrop.
In server1:
- install samba package
yum -y install samba samba-client - add service to startup
systemctl enable smb nmb - add configuration for share
vi /etc/samba/smb.conf
#in [global] section, find workgroup and replace existing name with myworkgroup
workgroup=myworkgroup
[myshare]
path=/share_data
writeable=no #it is default so you can avoid it
valid users = shiba @sales
write list = shiba
hosts allow = 192.168.122. - create /share_data directory for sharing
mkdir /share_data - start service
systemctl start smb nmb - set selinux file context
semanage fcontext -a -t samba_share_t “/share_data(/.*)?” - if sales group doesn’t exist, create it.
useradd shiba
groupadd sales
useradd -G sales user1
useradd user2
chown shiba.sales /share_data
chmod 2755 /share_data - Add users to samba
smbpasswd -a shiba
<give password twice, say userpass>
smbpasswd -a user1
<give password twice, say userpass>
smbpasswd -a user2
<give password twice, say userpass> - Add service to firewalld
firewall-cmd –add-service=samba –permanent
firewall-cmd –reload
In desktop1:
- install samba-client and cifs-utils
yum -y samba-client cifs-utils - Query for share in server
smbclient -L server1 #or give ipaddress of server, as a result you shoud see list of samba share in the server
<you will be asked for password> just press enter - create /smbshare
mkdir /smbshare - try mounting:
mount -o username=shiba,password=userpass //server1/myshare /smbshare
#if successful, add to fstab
echo “//server1/myshare /smbshare cifs defaults,username=shiba,password=userpass 0 0″ >> /etc/fstab - to verify if the user can write or not, create a file in /smbshare, if successful shiba user has wirte access:
touch /smbshare/test.txt - unmount /smbshare and try mounting with user1 who is a mermber of sales group. mount using credintial file (use for practicing alternative)
umount /smbshare
echo “username=user1″ > /root/user1.txt
echo “password=userpass” >> /root/user1.txt
mount -o credentials=/root/user1.txt //server1/myshare /smbshare - After successful mount of the share, try to write using:
touch /user1/test1.txt #it should fail, as @sales group have read-only access, but it is not included in write list. - try unmount and mount again using user2. You should not be able to mount the share, as user2 is not in valid users
echo “username=user2″ > /root/user2.txt
echo “password=userpass” >> /root/user2.txt
mount -o credentials=/root/users2.txt //server1/myshare /smbshare
Alternative option (using multiuser option, newly added to Centos/EL7):
In Desktop 1 mouting with multiuser option.
- install samba-client and cifs-utils
yum -y samba-client cifs-utils - Query for smb share in server1
smbclient -L server1 #or give ipaddress of server, as a result you shoud see list of samba share in the server
<you will be asked for password> just press enter - create /smbshare
mkdir /smbshare - try mounting:
mount -o sec=ntlmssp,multiuser,username=shiba,password=userpass //server1/myshare /smbshare
#if successful, add to fstab
echo “//server1/myshare /smbshare cifs multiuser,sec=ntlmssp,defaults,username=shiba,password=userpass 0 0″ >> /etc/fstab - To verify if the user can write or not, create a file in /smbshare, if successful shiba user has write access. switch to user shiba (for mounting with shiba, do same to other users). if user shiba doesn’t exist in your system, you can add it.
useradd shiba
su – shiba
cifscreds add server1
echo “shiba is writing to the file” /smbshare/test.txt
# go to your server and verify ownership, the file created should be owned by shiba in server1. - unmount /smbshare and try mounting with user1 who is a mermber of sales group. mount using credintial file (use for practicing alternative)
umount /smbshare
echo “username=user1″ > /root/user1.txt
echo “password=userpass” >> /root/user1.txt
mount -o sec=ntlmssp,multiuser,credentials=/root/user1.txt //server1/myshare /smbshare - after successful mount of the share, try to write using:
touch /user1/test1.txt
Note:it should fail, as @sales group have read-only access, but it is not included in write list. - Try unmount and mount again using user2. You should not be able to mount the share, as user2 is not in valid users.
echo “username=user2″ > /root/user2.txt
echo “password=userpass” >> /root/user2.txt
mount -o sec=ntlmssp,multiuser,credentials=/root/users2.txt //server1/myshare /smbshare
Leave a Reply