How to Install and Configure Samba Server On Debian 11.4

To Configure Samba Server With Debian 11.4

Introduction

Samba is a package that allows communication via the SMB (Server Message Block) protocol. An environment with hybrid components can be challenging. Even routine tasks such as sharing files and resources or sharing printers can be challenging. Without Samba, it is impossible to back up the Inter-OS environment and work with MS Active Directory.

Installation Procedure:

Step 1: Check the OS version by using the below command

root@debian:~# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Step 2: Check The IP Address by using the below command

root@debian:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:ea:5e:31 brd ff:ff:ff:ff:ff:ff
    altname enp2s1
    inet 192.168.6.131/23 brd 192.168.7.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feea:5e31/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

Step 3: Install the Samba server by using the below command

root@debian:~# apt install samba
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  dbconfig-common dbconfig-mysql default-mysql-client galera-4 icc-profiles-free
  libaio1 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdbd-mariadb-perl
  libdbi-perl libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-template-perl
  libjs-bootstrap4 libjs-codemirror libjs-jquery libjs-jquery-mousewheel
  libjs-jquery-timepicker libjs-jquery-ui libjs-openlayers libjs-popper.js
  libjs-sizzle libjs-sphinxdoc libjs-underscore libmariadb3 libonig5 libopengl0
  libterm-readkey-perl libzip4 mariadb-client-10.5 mariadb-client-core-10.5
  mariadb-common mariadb-server-10.5 mariadb-server-core-10.5 mysql-common node-jquery
  rsync socat
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  attr ibverbs-providers libcephfs2 libgfapi0 libgfrpc0 libgfxdr0 libglusterfs0
  libibverbs1 librados2 librdmacm1 liburing1 python3-cffi-backend python3-cryptography
  python3-dnspython python3-gpg python3-markdown python3-pygments
  python3-requests-toolbelt python3-samba python3-tdb python3-yaml samba-common
  samba-common-bin samba-dsdb-modules samba-vfs-modules tdb-tools
Suggested packages:
  python-cryptography-doc python3-cryptography-vectors python3-sniffio python3-trio
  python-markdown-doc python-pygments-doc ttf-bitstream-vera bind9 bind9utils ctdb
  ldb-tools ntp | chrony smbldap-tools winbind heimdal-clients
The following NEW packages will be installed:
  attr ibverbs-providers libcephfs2 libgfapi0 libgfrpc0 libgfxdr0 libglusterfs0
  libibverbs1 librados2 librdmacm1 liburing1 python3-cffi-backend python3-cryptography
  python3-dnspython python3-gpg python3-markdown python3-pygments
  python3-requests-toolbelt python3-samba python3-tdb python3-yaml samba samba-common
  samba-common-bin samba-dsdb-modules samba-vfs-modules tdb-tools
0 upgraded, 27 newly installed, 0 to remove and 26 not upgraded.
Need to get 23.8 MB of archives.
After this operation, 82.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up libgfapi0:amd64 (9.2-1) ...
Processing triggers for ufw (0.36-7.1) ...
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for libc-bin (2.31-13+deb11u6) ...

Step 4: Enable the samba service and reboot by using the below command

root@debian:~# systemctl enable smbd
Synchronizing state of smbd.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable smbd

Step 5: Check the status from smdb by using the below command

root@debian:~# systemctl status smbd
● smbd.service - Samba SMB Daemon
     Loaded: loaded (/lib/systemd/system/smbd.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2023-07-11 02:49:48 CDT; 41s ago
       Docs: man:smbd(8)
             man:samba(7)
             man:smb.conf(5)
   Main PID: 49706 (smbd)
     Status: "smbd: ready to serve connections..."
      Tasks: 4 (limit: 4623)
     Memory: 13.1M
        CPU: 243ms
     CGroup: /system.slice/smbd.service
             ├─49706 /usr/sbin/smbd --foreground --no-process-group
             ├─49708 /usr/sbin/smbd --foreground --no-process-group
             ├─49709 /usr/sbin/smbd --foreground --no-process-group
             └─49710 /usr/sbin/smbd --foreground --no-process-group

Jul 11 02:49:48 debian systemd[1]: Starting Samba SMB Daemon...
Jul 11 02:49:48 debian update-apparmor-samba-profile[49700]: grep: /etc/apparmor.d/samb>
Jul 11 02:49:48 debian update-apparmor-samba-profile[49703]: diff: /etc/apparmor.d/samb>
Jul 11 02:49:48 debian systemd[1]: Started Samba SMB Daemon.

Step 6: Restart the smdb service by using the below command

root@debian:~# systemctl restart smbd

Step 7: Check the status smdb service by using the below command

root@debian:~# systemctl status smbd
● smbd.service - Samba SMB Daemon
     Loaded: loaded (/lib/systemd/system/smbd.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2023-07-11 02:50:44 CDT; 7s ago
       Docs: man:smbd(8)
             man:samba(7)
             man:smb.conf(5)
    Process: 50195 ExecStartPre=/usr/share/samba/update-apparmor-samba-profile (code=ex>
   Main PID: 50199 (smbd)
     Status: "smbd: ready to serve connections..."
      Tasks: 4 (limit: 4623)
     Memory: 6.5M
        CPU: 126ms
     CGroup: /system.slice/smbd.service
             ├─50199 /usr/sbin/smbd --foreground --no-process-group
             ├─50201 /usr/sbin/smbd --foreground --no-process-group
             ├─50202 /usr/sbin/smbd --foreground --no-process-group
             └─50203 /usr/sbin/smbd --foreground --no-process-group

Jul 11 02:50:44 debian systemd[1]: Starting Samba SMB Daemon...
Jul 11 02:50:44 debian systemd[1]: Started Samba SMB Daemon.

Step 8: Create a folder by using the below command

root@debian:~# mkdir /smbshare

Step 9: Open the samba configuration file and add the user details by using the below command

root@debian:~# cp /etc/samba/smb.conf smb.conf.orig

Step 10: Add the samba user by using the below command

root@debian:~# vim /etc/samba/smb.conf
[samba-share]
        comment = samba share
        path = /smbshare
        read only = no
        browsable = yes
        writeable = yes

Step 11: Make smbuser owner for samba share user by using the below command

root@debian:~# useradd smbuser
root@debian:~# smbpasswd -a smbuser
New SMB password:
Retype new SMB password:
Added user smbuser.

Step 12: Restart the samba service by using the below command

root@debian:/smbshare# systemctl restart smbd

Step 13: Open an MS window client. Browse with the IP address of samba share and press enter as shown in the below image Step 14: Create a new file and see the file by using the below command

root@debian:/smbshare# touch user1

Step 15: Mount the share folder on Ms Windows’s client permanently as shown in the below image.

Conclusion:

By this how to configure Samba server with Debian 11 has come to an end.

FAQ
Q
What is the best way to set a Samba user's password?
A
WAY TO SET SAMBA PASSWORD IS smbpasswd -a
Q
How to add a Samba user?
A
Use This Useradd command
Q
How do you restart Samba?
A
sudo /etc/init. d/samba restart should be all you need to do.
Q
Which port Samba server works?
A
SMB ports are generally port numbers 139 and 445. Port 139 is used by SMB dialects that communicate over NetBIOS. It's a transport layer protocol designed to use in Windows operating systems over a network.
Q
What is the Samba configuration file?
A
/etc/samba/smb.conf