DEV Community

Cover image for How to set up a Samba Server in Ubuntu and share files seamlessly
Rizwan Hasan for TechLearners

Posted on

How to set up a Samba Server in Ubuntu and share files seamlessly

Before jumping into the topic, let me ask you a couple of questions. How you transfer your files from your one pc to another or pc to phone? You're probably gonna say about using a USB cable or Pendrive? Yeah, it's very common. But if I ask you how to share it through your local network where your every device is connected to your high-performance router with WiFi or LAN Cable. Can you share your files with one device to another simultaneously by using this local network? Can you stream and watch your favorite movie from your pc to your phone? I'll say yes, you can.

Some popular network protocol exists with this ability and maybe you've already heard of one or used one on your Windows PC or laptop already. Windows has a handy feature of drive sharing or a particular folder sharing across the local network which can be accessed from another device or the phone's also if they are on the same network. And Windows uses the SMB networking protocol or in short SAMBA. Using Samba on Windows is very easy with a couple of clicks and it'll up.

Accessing from Linux is also very easy but can we create this network in Linux? Yes, and it's not so tough because I'm here to break it down step by step. I'll only cover Ubuntu in this article because it's very popular and beginner-friendly. But if you need it on another distribution, you can comment me below and I'll glad to cover it. So, let's start with a basic definition of Samba.

โœด๏ธ What is Samba?

Samba is a free software re-implementation of the SMB(Server Message Block) networking protocol which was originally developed by Andrew Tridgell. It is the standard Windows interoperability suite of programs for Linux and Unix. Samba provides secure, stable, and fast file and print services for all clients using the SMB(Server Message Block)/CIFS(Common Internet File System) protocol.


โžก๏ธ Installation

  • Update repository cache ```shell

๐Ÿ’ฒ sudo apt update


* Install Samba package
```shell


๐Ÿ’ฒ sudo apt install samba


Enter fullscreen mode Exit fullscreen mode

โžก๏ธ Configurations

  • Creating a folder for share ```shell

๐Ÿ’ฒ mkdir /home//sambashare/


* Opening config file in terminal
```shell


๐Ÿ’ฒ sudo nano /etc/samba/smb.conf


Enter fullscreen mode Exit fullscreen mode
  • Config for sharing previously created folder
  • Add this config at the end of the file


[sambashare]
    comment = Samba on Ubuntu
    path = /home/<username>/sambashare
    read only = no
    browsable = yes


Enter fullscreen mode Exit fullscreen mode

Configuration

  • Start the service ```shell

๐Ÿ’ฒ sudo service smbd restart

---

###โžก๏ธ **Configuring Firewall**

* Add Samba allowance in [UFW (Uncomplicated Firewall)](https://wiki.ubuntu.com/UncomplicatedFirewall) 
```shell


๐Ÿ’ฒ sudo ufw allow samba


Enter fullscreen mode Exit fullscreen mode

Alt Text


โžก๏ธ Setting up a user account for Samba

  • Since Samba doesnโ€™t use the system account password, we need to set up a Samba password for our user account.
  • Username used must belong to a system account, else it wonโ€™t save.
  • Setting up User Accounts and Connecting to Share ```shell

๐Ÿ’ฒ sudo smbpasswd -a


![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/jf7tehtfqoyajfbk31i1.png)

---

###โžก๏ธ **Find your local IP**

* I'm using ifconfig to know my local IP

> Solution for ifconfig command not found in the system
```shell


๐Ÿ’ฒ sudo apt install net-tools


Enter fullscreen mode Exit fullscreen mode

Ifconfig


โžก๏ธ Samba status



๐Ÿ’ฒ sudo systemctl status smbd


Enter fullscreen mode Exit fullscreen mode

Samba status


โžก๏ธ Paste some file in the folder

Alt Text


โžก๏ธ Connect from Windows

  • Write your devices IP address in the red marked area following this format


\\IP_ADDRESS\\<FOLDER_NAME>


Enter fullscreen mode Exit fullscreen mode


\\192.168.1.41\sambashare


Enter fullscreen mode Exit fullscreen mode

Alt Text

๐Ÿ’˜ Connection successful

Alt Text


Best of Luck

Share your opinion in the discussion section below and of course the questions if any. Don't forget to follow us.

๐Ÿ’ก AND SUBSCRIBING to our YouTube TechLearnersInc and Telegram t.me/TechLearners will be amazing.

Top comments (3)

Collapse
 
krrishdhaneja profile image
Krrish Dhaneja

Would the steps be same for Manjaro?

Collapse
 
rizwan486 profile image
Rizwan Hasan

Not exactly same.

Collapse
 
krrishdhaneja profile image
Krrish Dhaneja

Um.. only apt would be replaced with pacman in install sambashare, maybe something like this->
sudo pacman -Syu
sudo pacman -Syy
sudo pacman -S sambashare