How to set up a Samba Server in Ubuntu and share files seamlessly
Tags: linux, ubuntu, tutorial, cloud
Published: 2021-01-07 21:14:57

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.

<br />
> 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](https://www.samba.org/) is a free software re-implementation of the [SMB(Server Message Block)](https://en.wikipedia.org/wiki/Server_Message_Block) networking protocol which was originally developed by [Andrew Tridgell](https://en.wikipedia.org/wiki/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
```
---

###➡️ **Configurations**

* Creating a folder for share
```shell
💲 mkdir /home/<username>/sambashare/
```

* Opening config file in terminal
```shell
💲 sudo nano /etc/samba/smb.conf
```

* Config for sharing previously created folder 
* Add this config at the end of the file

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

![Configuration](https://dev-to-uploads.s3.amazonaws.com/i/qrxwiwxpy9y46tt99v65.png)

* 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
```

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

---

###➡️ **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.

<br />

> * 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 <username>
```

![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
```

![Ifconfig](https://dev-to-uploads.s3.amazonaws.com/i/qkp5tcnek868k4n1el12.png)

---

###➡️ **Samba status**

```shell
💲 sudo systemctl status smbd
```

![Samba status](https://dev-to-uploads.s3.amazonaws.com/i/bm0fnacjyhcb90rvgz8a.png)

---

###➡️ **Paste some file in the folder**

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

---

###➡️ **Connect from Windows**

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

```
\\IP_ADDRESS\\<FOLDER_NAME>
```

```
\\192.168.1.41\sambashare
```

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

**💘 Connection successful**

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

---
![Best of Luck](https://dev-to-uploads.s3.amazonaws.com/i/qm2u6bsds1vjr1ci47b4.png)

*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**](https://www.youtube.com/c/TechLearnersInc) ***and Telegram*** [**t.me/TechLearners**](https://t.me/TechLearners) ***will be amazing.***