Samba Network Sharing
Introduction
Most Linux systems are the part of networks that also run Windows systems. Using Linux Samba
servers, your Linux and Windows systems can share directories and printers.
Samba is an open-source implementation of the Server Message Block (SMB) and Common Internet
File System (CIFS) protocols that provides file and print services between clients across various
operating systems
Samba Configuration File:
The default configuration file (/etc/samba/smb.conf) allows users to view their home
directories as a Samba share. It also shares all printers configured for the system as Samba
shared printers. In other words, you can attach a printer to the system and print to it from
the Windows machines on your network.
Samba Server and Samba Client Machine Details
[root@server ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain
::1 localhost localhost.localdomain
192.168.56.101 server.agoutam.com server
192.168.56.102 client.agoutam.com client
192.168.56.101 www.agoutam.com
Where :
Samba Server Run : 192.168.56.101 server.agoutam.com server
Samba Client Run : 192.168.56.102 client.agoutam.com client
Samba Services and Port for Firewall to open In order to Run Samba Service
Ports you need to open for two-way samba communication with Windows and Linux desktop systems.
NetBIOS-ns – 137/tcp # NETBIOS Name Service
netbios-dgm – 138/tcp # NETBIOS Datagram Service
netbios-ssn – 139/tcp # NETBIOS session service
microsoft-ds – 445/tcp # if you are using Active Directory
Port 445 (TCP) – NetBIOS was moved to 445 after 2000 and beyond, (CIFS)
# firewall-cmd --permanent --zone=public --add-service=samba
# firewall-cmd --reload
OR
# firewall-cmd --permanent --add-port=137/tcp
# firewall-cmd --permanent --add-port=138/tcp
# firewall-cmd --permanent --add-port=139/tcp
# firewall-cmd --permanent --add-port=445/tcp
To Install the Samba packages
[root@server ~]# yum install -y samba
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package samba.x86_64 0:4.6.2-8.el7 will be installed
--> Processing Dependency: samba-libs = 4.6.2-8.el7 for package:
samba-4.6.2-8.el7.x86_64
--> Processing Dependency: samba-common-tools = 4.6.2-8.el7 for
package: samba-4.6.2-8.el7.x86_64
--> Processing Dependency: libxattr-tdb-samba4.so(SAMBA_4.6.2)(64bit)
for package: samba-4.6.2-8.el7.x86_64
--> Processing Dependency: libxattr-tdb-samba4.so()(64bit) for
package: samba-4.6.2-8.el7.x86_64
--> Running transaction check
---> Package samba-common-tools.x86_64 0:4.6.2-8.el7 will be
installed---> Package samba-libs.x86_64 0:4.6.2-8.el7 will be
installed
Total download size: 1.3 M
Installed size: 3.7 M
Downloading packages:
(2/4): samba-4.6.2-8.el7.x86_64.rpm
(3/4): samba-common-tools-4.6.2-8.el7.x86_64.rpm
(4/4): samba-libs-4.6.2-8.el7.x86_64.rpm
----------------------------------------------------------------
Total
1.5 MB/s | 1.3 MB 00:00:00
Running transaction
Installing : pytalloc-2.1.9-1.el7.x86_64
Installing : samba-libs-4.6.2-8.el7.x86_64
Installing : samba-common-tools-4.6.2-8.el7.x86_64
Installing : samba-4.6.2-8.el7.x86_64
Verifying : pytalloc-2.1.9-1.el7.x86_64
Verifying : samba-libs-4.6.2-8.el7.x86_64
Verifying : samba-common-tools-4.6.2-8.el7.x86_64
Verifying : samba-4.6.2-8.el7.x86_64
Installed:
samba.x86_64 0:4.6.2-8.el7
Dependency Installed:
pytalloc.x86_64 0:2.1.9-1.el7 samba-common-
tools.x86_64 0:4.6.2-8.el7 samba-libs.x86_64
0:4.6.2-8.el7
Complete!
To Create Shared Folder for Network sharing
[root@server ~]# mkdir -v /sambasharing
mkdir: created directory ‘/sambasharing’
To provide Permission to Shared Folder
[root@server ~]# chown 770 /sambasharing
To Create File inside Samba Shared Directory
[root@server sambasharing]# touch file1 file2 file3
[root@server sambasharing]# ls
file1 file2 file3
To Create Samba User and Password
[root@server sambasharing]# useradd agsamba
[root@server sambasharing]# smbpasswd -a agsamba
New SMB password:
Retype new SMB password:
Added user agsamba.
[root@server sambasharing]#
To Create samba group
[root@server sambasharing]# groupadd smbusers
To change ownership of /sambasharing folder to smbusers
[root@server sambasharing]# chown :smbusers /sambasharing
To Add user agsamba to Secondary Group smbusers
[root@server sambasharing]# usermod -G smbusers agsamba
[root@server sambasharing]# grep smbusers /etc/group
smbusers:x:1006:agsamba
To view Group Information of agsamba User.
[root@server sambasharing]# id agsamba
uid=1005(agsamba) gid=1005(agsamba)
groups=1005(agsamba),1006(smbusers)
[root@server sambasharing]#
Verify Configuration changes using testparm command checks smb.conf
configuration file for internal correctness
[root@server sambasharing]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit
(16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[print$]"
Processing section "[sambadir]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
# Global parameters
[global]
server string = Samba server Version %v
workgroup = AGOUTAM SAMBA
log file = /var/log/samba/log.%m
max log size = 50
printcap name = cups
security = USER
idmap config * : backend = tdb
cups options = raw
hosts allow = 127. 192.168.56.
[homes]
comment = Home Directories
browseable = No
inherit acls = Yes
read only = No
valid users = %S %D%w%S
[printers]
comment = All Printers
path = /var/tmp
browseable = No
printable = Yes
create mask = 0600
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
create mask = 0664
directory mask = 0775
write list = root
#sambadir is Name of Samba Sharing and /sambasharing is shared folder
[sambadir]
comment = Centos7 Samba Share
path = /sambasharing
guest ok = Yes
read only = No
To Enable Samba Service at Boot time.
[root@server sambasharing]# systemctl enable smb
Created symlink from
/etc/systemd/system/multi-user.target.wants/smb.service to
/usr/lib/systemd/system/smb.service.
To Start Samba Service
[root@server sambasharing]# systemctl start smb
To Set up the correct SELinux context for /sambasharing
[root@server sambasharing]# semanage fcontext -a -t samba_share_t
"/sambasharing (/.*)?"
[root@server sambasharing]# restorecon -R /sambasharing
To Add Samba Service and open default port in firewall
[root@server sambasharing]# firewall-cmd --permanent --add-
service=samba
success
To View status of Samba Service
[root@server sambasharing]# systemctl status smb
? smb.service - Samba SMB Daemon
Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled;
vendor preset: disabled)
Active: active (running) since Mon 2017-10-23 11:29:55 IST; 2min
22s ago
Main PID: 2342 (smbd)
Status: "smbd: ready to serve connections..."
CGroup: /system.slice/smb.service
??2342 /usr/sbin/smbd
Oct 23 11:29:55 server systemd[1]: Starting Samba SMB Daemon...
Oct 23 11:29:55 server smbd[2342]: [2017/10/23 11:29:55.671610,
0] ../lib/...y)
Oct 23 11:29:55 server systemd[1]: Started Samba SMB Daemon.
Oct 23 11:29:55 server smbd[2342]: STATUS=daemon 'smbd' finished
starting...ns
Hint: Some lines were ellipsized, use -l to show in full.
Client Configuration to Connect to Samba server
To Install Samba client package
[root@client ~]# yum -y install samba-client samba-windbind
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package samba-client-4.6.2-8.el7.x86_64 already installed and latest
version
No package samba-windbind available.
Nothing to do
[root@client ~]#
Verifying client instance i.e connecting from client Computer
smbclient <path> <credentials>
smbclient //192.168.56.101/sambadir -U agsamba
[root@client ~]# smbclient //192.168.56.101/sambadir -U agsamba
Enter SAMBA\agsamba's password:
Domain=[SERVER] OS=[Windows 6.1] Server=[Samba 4.6.2]
smb: \> ls
. D 0 Mon Oct 23 11:09:23
2017
.. DR 0 Mon Oct 23 11:06:58
2017
file1 N 0 Mon Oct 23 11:09:23
2017
file2 N 0 Mon Oct 23 11:09:23
2017
file3 N 0 Mon Oct 23 11:09:23
2017
10873856 blocks of size 1024. 3439320 blocks
available
smb: \>
To View Information of Samba Shared Directory
[root@client ~]# smbclient -L //192.168.56.101 -N
Anonymous login successful
OS=[Windows 6.1] Server=[Samba 4.6.2]
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
sambadir Disk Centos7 Samba Share
IPC$ IPC IPC Service (Samba server Version
4.6.2)
Anonymous login successful
OS=[Windows 6.1] Server=[Samba 4.6.2]
Server Comment
--------- -------
Workgroup Master
--------- -------
To Mount Samba file system on Client Machine
To install Packaged required for Mounting ,yum install cifs-utils
[root@client ~]# yum install -y cifs-utils
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package cifs-utils-6.2-10.el7.x86_64 already installed and latest
version
Nothing to do
To Create Mount Directory in Client Machine
[root@client ~]# mkdir /smb
To Create Mount Point for Samba Network Sharing
[root@client ~]# mount.cifs //192.168.56.101/sambadir /smb -o
user=agsamba
Password for agsamba@//192.168.56.101/sambadir: *******
[root@client ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 21G 7.2G 14G 34% /
devtmpfs devtmpfs 905M 0 905M 0% /dev
tmpfs tmpfs 920M 0 920M 0% /dev/shm
tmpfs tmpfs 920M 8.8M 911M 1% /run
tmpfs tmpfs 920M 0 920M 0%
/sys/fs/cgroup
/dev/sda1 xfs 1014M 178M 837M 18% /boot
tmpfs tmpfs 184M 12K 184M 1%
/run/user/42
tmpfs tmpfs 184M 0 184M 0% /run/user/0
//192.168.56.101/sambadir cifs 11G 7.1G 3.3G 69% /smb
To Access Samba Server from Window machine
Step 1 :Got To Run And Type \\192.68.56.101\sambadir
Step 2:Window will open to Provide password for authentication Provide Password
Step 3:To View Samba Shared Directory in Window ,In Browser Type IP Address of Samba
Server Host Machine
Step 4:To View Content of Samba Shared Directory,Go to sambadir where sambadir is
name of samba Shared folder