Samba is a open-source software that can be used on both Windows and Linux for sharing files, folders, and printers between them. It has been used for many years with several different protocols (SMB/CIFS protocol), as well as their subcategories.
- Let’s install samba server, client and policycoreutils for SELinux
[admin@localhost ~]$ sudo dnf install samba samba-client policycoreutils-python-utils
- Create sambashare directory in under “ / “ as follows give necessary permission.
sudo mkdir /sambashare
sudo chmod -R 777 sambashare/
- Check the SELinux boolean for samba and enable them if they are not enable.
[admin@localhost ~]$ getsebool -a | grep samba_export
samba_export_all_ro –> off
samba_export_all_rw –> off
[admin@localhost ~]$ getsebool -a | grep samba_share_nfs
samba_share_nfs –> off
[admin@localhost ~]$ sudo setsebool -P samba_export_all_ro=1 samba_export_all_rw=1 samba_share_nfs=1
[admin@localhost ~]$ getsebool -a | grep samba_export
samba_export_all_ro –> on
samba_export_all_rw –> on
[admin@localhost ~]$ getsebool -a | grep samba_share_nfs
samba_share_nfs –> on
- Add approriate SELinux context for sambashare folder.
[admin@localhost ~]$ sudo semanage fcontext -at samba_share_t “/sambashare/(/.*)?”
[admin@localhost ~]$ restorecon /sambashare/
[admin@localhost ~]$ ll -Zd /sambashare/
drwxr-xr-x. 2 root root unconfined_u:object_r:default_t:s0 4096 Jul 6 21:44 /sambashare/
- Allow the Samba Service via Firewall
[admin@localhost ~]$ sudo firewall-cmd –permanent –add-service=samba
[sudo] password for admin:
success
[admin@localhost ~]$ sudo firewall-cmd –reload
success
- Test the Samba Configuration settings.
[admin@localhost ~]$ testparm
Load smb config files from /etc/samba/smb.conf
Loaded services file OK.
Weak crypto is allowed
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
# Global parameters
[global]
interfaces = lo enp0s4 192.168.1.
log file = /var/log/samba/%m.log
security = USER
server string = 192.168.1.123
workgroup = SAMBA
idmap config * : backend = tdb
hosts allow = 127. 192.168.1.124
[sambashare]
comment = /sambashare
guest ok = Yes
path = /sambashare
read only = No
valid users = user1
write list = user1
- Create Samba user and password
[admin@localhost ~]$ sudo useradd user1
[sudo] password for admin:
[admin@localhost ~]$ sudo smbpasswd -a user1
New SMB password:
Retype new SMB password:
Added user user1.
- The “pdbedit” program is used to manage the user’s accounts stored in the “sam” database and can be run only by root.
[admin@localhost ~]$ sudo pdbedit -Lv
Unix username: user1
NT username:
Account Flags: [U ]
User SID: S-1-5-21-732476358-3035687843-3070369674-1000
Primary Group SID: S-1-5-21-732476358-3035687843-3070369674-513
Full Name:
Home Directory: \\localhost\user1
HomeDir Drive:
Logon Script:
Profile Path: \\localhost\user1\profile
Domain: LOCALHOST
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: Wed, 06 Feb 2036 15:06:39 GMT
Kickoff time: Wed, 06 Feb 2036 15:06:39 GMT
Password last set: Tue, 07 Jul 2020 00:16:25 BST
Password can change: Tue, 07 Jul 2020 00:16:25 BST
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
[admin@localhost ~]$
- Enable and start the samba service
[admin@localhost ~]$ sudo systemctl start/enable smb
[admin@localhost ~]$ sudo systemctl status smb
● smb.service – Samba SMB Daemon
Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2020-07-07 00:20:11 BST; 9s ago
Samba Client on Linux
- Installing Samba Client
[root@localhost ]# dnf install samba samba-client cifs-utils
- Mount sambashare folder in Samba Server with /mnt
[root@localhost ~]# mount //192.168.1.123/sambashare /mnt –verbose -o user=user1,pass=123456
mount.cifs kernel mount options: ip=192.168.1.123,unc=\\192.168.1.123\sambashare,user=user1,pass=********
| [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 17M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda3 6.1G 1.4G 4.4G 25% / tmpfs 378M 0 378M 0% /run/user/0 //192.168.1.123/sambashare 6.1G 1.8G 4.4G 29% /mnt |
- Samba server auto mount (with credential file)
[root@localhost ~]# vi /etc/samba/sharecred
user=user1
pass=123456
[root@localhost ~]# vi /etc/fstab
UUID=13eb116b-abb0-4d7e-895a-fd5bee45cc30 swap swap defaults 0 0
//192.168.1.123/sambashare /mnt cifs rw,credentials=/etc/samba/sharecred 1 1
- Mount the above share as below
[root@localhost ~]# mount -a
| [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 17M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda3 6.1G 1.4G 4.4G 25% / tmpfs 378M 0 378M 0% /run/user/0 /dev/sda1 976M 133M 777M 15% /boot //192.168.1.123/sambashare 6.1G 1.8G 4.3G 29% /mnt |
Samba Client on Windows
- Add samba window client into smb.conf file as follows. It has IP address of 192.168.1.106.
[admin@localhost ~]$ sudo vi /etc/samba/smb.conf

- Then enter the samba server (with IP 192.168.1.123) for search as follows.

- Now enter the samba username and password to login to samba server







































