This guide explains the Installation and configuration of Samba server on Ubuntu Server 16.04 (xenial). Samba is an Open-Source file sharing utility using the CIFS protocol, specifically aimed at allowing Windows and Linux servers to access the same file-systems. The normal setup is to have the data drives mounted on a Linux server and shared out using Samba and NFS. The Windows clients can then mount those drives using a Samba client and the Linux clients can mount them with NFS. Samba provides file and print services for various Microsoft Windows clients. Now we are going to install samba on newly installed minimal Ubuntu Server. and in my case I have two client operating systems:
Windows 10 192.168.0.110
Lubuntu Desktop 192.168.0.155
Ubuntu Server(For NAS) 192.168.0.151
Contents :
1. Installing and Configuring Samba Server
Now first we configure our Ubuntu Server. SSH into your Ubuntu Server and start a root shell by
nano : A Beginners Guide to nano text editor
vim : A Beginners Guide to vi / vim text editor
open the smb.conf file
1. Guest Sharing with Samba :
Now we are going to create a Guest Sharing folder which users can access without any authentication or password. Open up /etc/samba/smb.conf file again and append the following lines
$ Accessing the Guest\Anonymous Sharing in Windows Machine :
Now to access the Anonymous Share in Windows machine you have to make sure that the windows machine must be in the same workgroup. To check the value in the windows Machine run the following command in command prompt
if its not WORKGROUP then change it to WORKGROUP. To do that right click on "My Computer" or "This PC" icon and go to properties then click on "Change settings" which is in the right side of the window.
Now click on the Change button
now at the "Computer Name/Domain Changes" change the workgroup name, save it and re-start the computer. Now after the re-start go to the search box and type 'run' and hit enter to start 'Run' or just press Window_button+R.
now at 'Run' type "\\Ubuntu_server_ip_address" in my case which is "\\192.168.0.151" then hit enter
and if everything is fine then you can see the "Anonymous" Share folder.
To map it as network drive just right click on the 'Anonymous' Folder icon and click on the 'Map network drive', select the Drive letter and click on Finish button.
$ Accessing the Anonymous sharing in Linux :
In Linux start your file Manager and type the following "smb://Ubuntu_server_ip_address" at address bar and hit enter
after that click on 'anonymous' and then connect.
2. Secured Sharing with Samba :
For password-protected share, we need to create a group and user to access the samba server. So first we need to create a group. I will create a group 'securesmb' with username 'drap' with password '12345'. creating a user group
notice that you have to type the password twice in smbpasswd command. now create the folder with the name 'secured' in the /samba folder and give permissions :
$ Accessing the Secured Sharing in Windows :
To access the Secured folder on window machine again start 'run', type the ip address of samba server and hit enter
then click on the secured folder and put the credentials, in my case it is
username : drap
password : 12345
then click on Ok.
$ Accesing the Anonymous sharing in Linux :
In linux do the same thing as above again and click on the 'secured' folder, select 'connect as user' and put your credentials here
username : drap
password : 12345
Now we have a successfully configured Samba server with an anonymous and a secured share on Ubuntu server 16.04.
Windows 10 192.168.0.110
Lubuntu Desktop 192.168.0.155
Ubuntu Server(For NAS) 192.168.0.151
Contents :
- Installing and Configuring Samba Server
- Guest Sharing with Samba
- Accessing the Guest\Anonymous Sharing in Windows Machine
- Accessing the Anonymous sharing in Linux
- Secured Sharing with Samba
- Accessing the Secured Sharing in Windows
- Accessing the Anonymous sharing in Linux
1. Installing and Configuring Samba Server
Now first we configure our Ubuntu Server. SSH into your Ubuntu Server and start a root shell by
sudo -s
1. Update the repositories and upgrade the distribution apt-get update
apt-get upgrade
2. install the samba server and its dependencies apt-get install -y samba samba-common python-glade2 system-config-samba
now to check the which version of samba is installed, typesamba -V
in my system it is 4.3.11-Ubuntu. Now to configure samba server, we need to edit the /etc/samba/smb.conf file. But before that create a backup of current configuration file. to do that just copy the smb.conf to smb.conf.bak cp -pf /etc/samba/smb.conf /etc/samba/smb.conf.bak
now clear the content of smb.conf file by cat /dev/null > /etc/samba/smb.conf
now open the smb.conf file in text editor nano or vim. I am using vim editor. If you are new to nano or vim then check out my other posts:nano : A Beginners Guide to nano text editor
vim : A Beginners Guide to vi / vim text editor
open the smb.conf file
vi /etc/samba/smb.conf
and put the below lines in it [global]
workgroup = WORKGROUP
server string = Samba Server %s
netbios name = ubuntu
security = user
map to guest = bad user
dns proxy = no
then save the file.1. Guest Sharing with Samba :
Now we are going to create a Guest Sharing folder which users can access without any authentication or password. Open up /etc/samba/smb.conf file again and append the following lines
[Anonymous]
path = /samba/anonymous
browsable = yes
writable = yes
guest ok = yes
read only = no
force user = nobody
now create a directory for the anonymous share. mkdir -p /samba/anonymous
and set the permissions chmod -R 0775 /samba/anonymous
chown -R nobody:nogroup /samba/anonymous
and then restart samba to apply the new configuration service smbd restart
$ Accessing the Guest\Anonymous Sharing in Windows Machine :
Now to access the Anonymous Share in Windows machine you have to make sure that the windows machine must be in the same workgroup. To check the value in the windows Machine run the following command in command prompt
net config wrokstation
if its not WORKGROUP then change it to WORKGROUP. To do that right click on "My Computer" or "This PC" icon and go to properties then click on "Change settings" which is in the right side of the window.
Now click on the Change button
now at 'Run' type "\\Ubuntu_server_ip_address" in my case which is "\\192.168.0.151" then hit enter
and if everything is fine then you can see the "Anonymous" Share folder.
To map it as network drive just right click on the 'Anonymous' Folder icon and click on the 'Map network drive', select the Drive letter and click on Finish button.
$ Accessing the Anonymous sharing in Linux :
In Linux start your file Manager and type the following "smb://Ubuntu_server_ip_address" at address bar and hit enter
after that click on 'anonymous' and then connect.
2. Secured Sharing with Samba :
For password-protected share, we need to create a group and user to access the samba server. So first we need to create a group. I will create a group 'securesmb' with username 'drap' with password '12345'. creating a user group
addgroup securesmb
add a user drap to securesmb useradd drap -G securesmb
setting up the password for the user 'drap' smbpasswd -a drap
notice that you have to type the password twice in smbpasswd command. now create the folder with the name 'secured' in the /samba folder and give permissions :
mkdir -p /samba/secured
cd /samba
chmod -R 0770 secured
chown root:securesmb secured
Now we need to edit the samba configuration file, open the smb.conf and add the following lines vi /etc/samba/smb.conf
[secured]
path = /samba/secured
valid users = @securesmb
guest ok = no
writable = yes
browsable = yes
now restart the smb service service smbd restart
$ Accessing the Secured Sharing in Windows :
To access the Secured folder on window machine again start 'run', type the ip address of samba server and hit enter
then click on the secured folder and put the credentials, in my case it is
username : drap
password : 12345
then click on Ok.
$ Accesing the Anonymous sharing in Linux :
In linux do the same thing as above again and click on the 'secured' folder, select 'connect as user' and put your credentials here
username : drap
password : 12345
Now we have a successfully configured Samba server with an anonymous and a secured share on Ubuntu server 16.04.