Bootstrap FreeKB - Samba (File Server) - Install Samba on Linux
Samba (File Server) - Install Samba on Linux

Updated:   |  Samba (File Server) articles

Your Linux distributions package manager can be used to install Samba.

  • apt-get on Debian distributions
  • yum on Red Hat 7 distributions (CentOS, Fedora, Red Hat)
  • dnf on Red Hat 8 distributions (CentOS, Fedora, Red Hat)

In this example, dnf is used to install Samba.

dnf install samba
dnf install cifs-utils

 

Allow the samba, http and https services in iptables or firewalld.

firewall-cmd --add-service=samba --permanent
firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent
firewall-cmd --reload

 

If the share is running on Amazon Web Services (AWS), you may need to add inbound rules to the Security Group to allow UDP ports 137 and 138 and TCP ports 139 and 587.

 

 

The ps command can be used to determine if your system is using init or systemd. If PID 1 is init, then you will use the service command. If PID 1 is systemd, then you will use the systemctl command.

If your system is using systemd, use the systemctl command to start and enable Samba.

systemctl enable smb
systemctl start smb
systemctl status smb

 

If your system is using init, use the chkconfig and service commands to start and enable Samba.

chkconfig enable on
service start smb
service status smb

 


Disable Printers

I almost always update /etc/samba/smb.conf to not share printers.

[global]
        workgroup = SAMBA
        security = user
        passdb backend = tdbsam

        load printers = no
        printing = bsd
        printcap name = /dev/null
        disable spoolss = yes

[homes]
        comment = Home Directories
        valid users = %S, %D%w%S
        browseable = No
        read only = No
        inherit acls = Yes

 


Add User to Samba

You will need to configure at least one user account that will be used when connecting to Samba. There are three "backends" (or ways) of storing usernames and password with Samba. Check out my article user password backends (tdbsam smbpasswd ldapsam). For example, the useradd command can be used to create john.doe user account.

useradd -p itsasecret -d /home/john.doe -s /bin/bash john.doe

 

And then the smbpasswd -a command can be used to add john.doe to the Samba database.

~]# smbpasswd -a john.doe
New SMB password:
Retype new SMB password:
Added user john.doe.

 

The pdbedit --list --smbpasswd-style command can be used to verify the user was added to the SMB database. The output should be indetical to the smb.passwd file.

~]# docker exec samba pdbedit --list --smbpasswd-style
john.doe:1000:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:43A29EF878C2498C6960672E21CA9B9D:[U          ]:LCT-616C00EF:

~]# docker exec samba cat /etc/samba/smb.passwd
john.doe:1000:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:43A29EF878C2498C6960672E21CA9B9D:[U          ]:LCT-616C00EF:

 

The smbclient command can be used to see if you are able to connect to a share with a certain user and their password (john.doe in this example).

smbclient --list //$(hostname -s)/share --user john.doe

 

 

You should now be able to Share a storage drive on Linux using Samba.




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 8056c0 in the box below so that we can be sure you are a human.