Here, Today! let’s discuss samba file share service with Ubuntu 20.04 LTS. If you need to share files between Linux and MS Windows Systems, CIFS or SMB is the way to go. The CIFS protocol is a server-client model. The system that host file to share, need to run Samba server as well.CIFS is an extension of SMB or server message block, a protocol developed by Microsoft. In Linux, we can use Samba software to connect CIFS-SMB shares. Also, in a basic set of default samba configurations, there is a list of shares or locations. By default, these locations with few restrictions are available too for the remote client to access.
Samba services how work with Ubuntu 20.04 LTS, this is what we will learn today. Let’s begin.
What you will learn:
- Installing the package, with examples.
- How to configure services.
- Finally, how to mount and use samba shares.
- An Ubuntu 20.04 LTS Machine.
- Also, MS Windows Desktop.
- Samba packages, of course for Ubuntu.
- Good internet connectivity.
Get Samba File share services ready:
Let’s get the Server ready first. Go and download Ubuntu OS. Second, install all required software as well.
Make required file changes
Install samba packages
#apt install samba
Let’s have a look is samba services are running proper or not?
# systemctl status smbd
Let’s see which files are visible in Samba default directory, will look something like below:
#cd /etc/samba/ && ls gdbcommands smb.conf tls
Edit smb.conf file, it is recommended to take a backup of original file first.
Create a shred directory which you would be using to get accessed from MS Windows client, in our example we created folder named as “sambashare”.
# mkdir /home/ubnt/sambashare
Let’s edit /etc/samba/smb.conf file, Make required changed as per below, add changes at bottom of the .conf file:
# nano /etc/samba/smb.conf [Samba-Windows-Share] comment = for windows share path = /home/ubnt/sambashare read only = no browsable = yes
Press ctrl+o followed by ctrl+x to save and exit from file.
Allow samba on firewall and start service.
#ufw allow samba Rules updated Rules updated (v6) #service smbd restart
Setup Samba password and access shared folder
As, samba do not use default user’s password. Let’s defile samba password for existing user, in our case user is ubnt.
# sudo smbpasswd -a ubnt
Change file permissions for shared folder, so that end user can add or remove files, defile permissions as per your need.
# chmod 777 /home/ubnt/sambashare/
Now, Samba server is ready, lets switch to MS Windows and see. Open Run and provide Samba server IP Address. In our scenario that IP address was 192.168.1.239.
press enter, shared folder creds which we have created in previous step is visible:
Give user id and password created recently with smbpasswd command, in my scenario first attempt login didn’t work, but don’t worry, give another try. it will work.
Lets try to create folder or file and see, whether that file is visible in Linux Machine or not. I have created Test_Folder and Test_File.
Lets have a look in Ubuntu Samba server, if these files are visible or not.
Bingo! we have created and tested samba server successfully. Give a try!!
I don’t know how to find what is the Samba server’s IP address on my PC.
you make it look so easy!
How to troubleshoot? My linux server is pingable from my windows laptop. The ss -pant | sort -k 6 command clearly shows that smbd is listening on ports TCP 445 and 139 on both IPv4 and IPv6. I have nmbd running as well, but it’s listening on UDP ports. 137 and 138. I looked at iptables and I see:
[email protected]:/etc/samba# iptables -L -n | fgrep -i udp
ufw-skip-to-policy-input udp — 0.0.0.0/0 0.0.0.0/0 udp dpt:137
ufw-skip-to-policy-input udp — 0.0.0.0/0 0.0.0.0/0 udp dpt:138
ufw-skip-to-policy-input udp — 0.0.0.0/0 0.0.0.0/0 udp dpt:67
ufw-skip-to-policy-input udp — 0.0.0.0/0 0.0.0.0/0 udp dpt:68
ACCEPT udp — 0.0.0.0/0 0.0.0.0/0 udp spt:67 dpt:68
ACCEPT udp — 0.0.0.0/0 18.104.22.168 udp dpt:5353
ACCEPT udp — 0.0.0.0/0 22.214.171.124 udp dpt:1900
ACCEPT udp — 0.0.0.0/0 0.0.0.0/0 ctstate NEW
ACCEPT udp — 0.0.0.0/0 0.0.0.0/0 multiport dports 137,138 /* ‘dapp_Samba’ */
I figured out the answer (actually, I found the answer on another page, Canonical Ubuntu Server docs https://ubuntu.com/server/docs/samba-file-server ): restart both the smbd and nmbd with the command:
systemctl restart smbd.service nmbd.service