How to Install and Configure Samba on Ubuntu 16.04 or 18.04
This post will guide you how to install and configure a Samba server on your Ubuntu Linux 18.04 or 16.04. How do I install Samba a Ubuntu Linux system.
- What is Samba?
- Prerequisites
- Step1: Installing Samba
- Step2: Setting Up Samba
- Step3: Connecting to Samba Share
What is Samba?
Samba is the standard Windows interoperability suite of programs for Linux and Unix.
Samba is an open source software that provides seamless file and print services to SMB/CIFS clients. Samba is the standard Windows interoperability suite of programs for Linux and Unix.
Samba is Free Software licensed under the GNU General Public License, the Samba project is a member of the Software Freedom Conservancy. If your windows systems and Ubuntu systems are on the same network, and you can use Samba + SMB/CIFS to enable files, printers, and other shared resources. So You can share files from your Linux system with Windows systems, including Windows 10,7, etc.
Prerequisites
- Before you get started with this post, and you need to have a non-root user with sudo privileges so that you can update or install packages under Ubuntu system.
- You need to make sure that both Windows and Ubuntu Linux systems are on the same network or in the same workstation domain.
- Before you begin, you also need to update the package index and all installed packages to the latest version on your Ubuntu system with the following steps:
$ sudo apt update $ sudo apt upgrade
Step1: Installing Samba
Samba package is available from the default Ubuntu repositories. So you just need to install it on your Ubuntu system with the following apt command, type:
$ sudo apt install samba
Outputs:
devops@devops:~$ sudo apt install samba
[sudo] password for devops:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
attr ibverbs-providers libcephfs2 libibverbs1 libnl-route-3-200 librados2 python-crypto python-dnspython python-ldb python-samba python-tdb samba-common samba-common-bin
samba-dsdb-modules samba-vfs-modules tdb-tools
Suggested packages:
python-crypto-doc python-gpgme bind9 bind9utils ctdb ldb-tools smbldap-tools winbind heimdal-clients
The following NEW packages will be installed:
attr ibverbs-providers libcephfs2 libibverbs1 libnl-route-3-200 librados2 python-crypto python-dnspython python-ldb python-samba python-tdb samba samba-common samba-common-bin
samba-dsdb-modules samba-vfs-modules tdb-tools
0 upgraded, 17 newly installed, 0 to remove and 137 not upgraded.
Need to get 7,798 kB of archives.
After this operation, 47.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.aliyun.com/ubuntu bionic/main amd64 python-dnspython all 1.15.0-1 [84.9 kB]
Get:2 http://mirrors.aliyun.com/ubuntu bionic/main amd64 python-crypto amd64 2.6.1-8ubuntu2 [244 kB]
Get:3 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 python-ldb amd64 2:1.2.3-1ubuntu0.1 [30.9 kB]
Get:4 http://mirrors.aliyun.com/ubuntu bionic/main amd64 python-tdb amd64 1.3.15-2 [11.1 kB]
Get:5 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 python-samba amd64 2:4.7.6+dfsg~ubuntu-0ubuntu2.11 [1,923 kB]
Get:6 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 samba-common all 2:4.7.6+dfsg~ubuntu-0ubuntu2.11 [71.3 kB]
Get:7 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 samba-common-bin amd64 2:4.7.6+dfsg~ubuntu-0ubuntu2.11 [520 kB]
……
Setting up python-tdb (1.3.15-2) ...
Setting up samba-common (2:4.7.6+dfsg~ubuntu-0ubuntu2.11) ...
Creating config file /etc/samba/smb.conf with new version
Setting up libnl-route-3-200:amd64 (3.2.29-0ubuntu3) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for systemd (237-3ubuntu10.23) ...
Setting up tdb-tools (1.3.15-2) ...
update-alternatives: using /usr/bin/tdbbackup.tdbtools to provide /usr/bin/tdbbackup (tdbbackup) in auto mode
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up samba-dsdb-modules (2:4.7.6+dfsg~ubuntu-0ubuntu2.11) ...
Setting up attr (1:2.4.47-2build1) ...
Setting up python-ldb:amd64 (2:1.2.3-1ubuntu0.1) ...
Setting up libibverbs1:amd64 (17.1-1ubuntu0.1) ...
Setting up python-samba (2:4.7.6+dfsg~ubuntu-0ubuntu2.11) ...
Setting up librados2 (12.2.12-0ubuntu0.18.04.1) ...
Setting up libcephfs2 (12.2.12-0ubuntu0.18.04.1) ...
Setting up ibverbs-providers:amd64 (17.1-1ubuntu0.1) ...
Setting up samba-common-bin (2:4.7.6+dfsg~ubuntu-0ubuntu2.11) ...
Setting up samba (2:4.7.6+dfsg~ubuntu-0ubuntu2.11) ...
Samba is not being run as an AD Domain Controller, masking samba-ad-dc.service.
Please ignore the following error about deb-systemd-helper not finding samba-ad-dc.service.
Created symlink /etc/systemd/system/multi-user.target.wants/nmbd.service → /lib/systemd/system/nmbd.service.
Failed to preset unit: Unit file /etc/systemd/system/samba-ad-dc.service is masked.
/usr/bin/deb-systemd-helper: error: systemctl preset failed on samba-ad-dc.service: No such file or directory
Created symlink /etc/systemd/system/multi-user.target.wants/smbd.service → /lib/systemd/system/smbd.service.
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for systemd (237-3ubuntu10.23) ...
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for ufw (0.36-0ubuntu0.18.04.1) ...
devops@devops:~$
Once the installation of Samba package is completed, and the Samba service should be started automatically. So you check if the Samba server is running or not by executing the following command:
$ systemctl status nmbd
Outputs:
devops@devops:~$ systemctl status nmbd nmbd.service - Samba NMB Daemon Loaded: loaded (/lib/systemd/system/nmbd.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2019-08-29 11:40:20 EDT; 47s ago Docs: man:nmbd(8) man:samba(7) man:smb.conf(5) Main PID: 9647 (nmbd) Status: "nmbd: ready to serve connections..." Tasks: 1 (limit: 1123) CGroup: /system.slice/nmbd.service └─9647 /usr/sbin/nmbd --foreground --no-process-group Aug 29 11:40:20 devops systemd[1]: Starting Samba NMB Daemon... Aug 29 11:40:20 devops systemd[1]: Started Samba NMB Daemon.
From the above output, you should see that the NMB service is in Active and running state. So far, Samba has been installed on your Ubuntu Linux server.
You can also check if the installation of Samba was successful by running the following command:
$ whereis samba
The output should look something like below:
devops@devops:~$ whereis samba
samba: /usr/sbin/samba /usr/lib/x86_64-linux-gnu/samba /etc/samba /usr/share/samba /usr/share/man/man7/samba.7.gz /usr/share/man/man8/samba.8.gz
Step2: Setting Up Samba
Now you need to create a directory for it to share, type:
$ mkdir /home/devops/sambashare/
Note: “devops” is you logging user. “sambashare” is a new folder in your home directory which we will share later.
Next, you need to configure the configuration file of Samba is located at /etc/samba/smb.conf. And you need to add your newly shared directory into Samba configuration file. Open the configuration file with your vim/nano text editor, type:
$ sudo vim /etc/samba/smb.conf
Adding the following lines at the botton of the file:
[sambashare] comment = Samba on Ubuntu path = /home/devops/sambashare read only = no browsable = yes
Save and close the file.
Note:
- [sambashare]: The name inside the brackets is the name of our share.
- comment: A brief description of the share.
- path: The directory of our share.
- read only: Permission to modify the contents of the share folder is only granted when the value of this directive is no.
- browsable: When set to yes, file managers such as Ubuntu’s default file manager will list this share under “Network”.
Then you need to restart Samba service, type:
$ sudo systemctl restart smbd
Step3: Connecting to Samba Share
Since Samba server doesn’t user the system account password, you need to setup a Samba password for your user account by running the following command:
$ sudo smbpasswd -a devops
Outputs:
devops@devops:~$ sudo smbpasswd -a devops
New SMB password:
Retype new SMB password:
Added user devops.
devops@devops:~$
Then you can open up your file Manager and type the following address to access the shared file or directory from Samba server.
\\ip-address\sambashare
Note: the IP address is the Samba server Ip address and “sambashare” is the name of the share in your samba server.
Conclusion
You should know that how to install a Samba Server on your Ubuntu or Debian Linux. If you want to see more detailed information about Samba, you can directly go to its official web site.