Create a Network Share in Linux using Samba via CLI and access using Samba Client

Setting up the share on Linux

Install Samba:

$ sudo apt-get update
$ sudo apt-get install samba

For creating a secured share, make a system account for authentication to access samba shares, here I named the user “shareuser” in an obvious way you can, of course, pick any name:

$ sudo useradd shareuser
$ sudo passwd shareuser
Update password for the user “shareuser”.

Check if the user has been added successfully:

$ awk -F':' '{ print $1}' /etc/passwd
shareuser” added successfully

Add this account in smbpasswd file to be used by samba authentication:

$ sudo smbpasswd -a shareuser

Configure the “shared” directory (or whatever you choose to name your directory that is to be shared):

$sudo mkdir /opt/shared

Make a safe backup copy of the original smb.conf file to your home folder, in case you make an error:

$ sudo cp /etc/samba/smb.conf ~

Edit Samba configuration file “/etc/samba/smb.conf” and add the following at the very end of the file:

Here replace [shared] with the name of your directory, modify the path accordingly too, and replace “shareuser” with whatever you chose to name your user.

Restart smb and nmb services of the system:

$ systemctl restart smbd.service
$ systemctl restart nmbd.service

Use testparm command to check your smb.conf for any syntax errors:

$ testparm
If there are no syntax errors you should be able to see something like this, with the [shared] entry at the bottom.

Thus, we created a shared folder named “shared” with “shareuser” as the username to be used for accessing this folder on another machine.

Access the SMB network share on Linux:

Installing Samba client will give you a CLI to work with your SMB share:

$ sudo apt-get install smbclient

List all shares available on the host using the IP address or hostname:

$ smbclient -L //<HOST_IP_OR_NAME>/<folder_name> -U <user>

Here <user> is the user we created in the host machine. Connect to the shared folder using:

$ smbclient //<HOST_IP_OR_NAME>/<folder_name> -U <user>

Note: The default user group of samba is "WORKGROUP".

You can type ‘h’ to get help with smbclient. For instance ‘ls’ would show the contents of the shared folder:

Troubleshoot Option- If you’re getting permission denied error when trying to modify the content of the shared folder, modify ownership and permission for the folder:

$ sudo chown <username>:<groupname> /<path to shared folder>
$ sudo chmod 770 /<path to shared folder>

Full Stack Web Developer | Graduate student of MS in Computer Science at The University of Texas at Rio Grande Valley

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

CS 371p: Blog #12

Towards Ansible: Test Machine Setup and Tool Familiarization

Tech assessment challenges

Five Minute Kubernetes Installation With k3OS

Best development practices are all about speed and trust

Python Brazil 2017: “People > Technology”

Clean Code: Always Keep Refactoring!

Monitoring theory, from scratch — metrics and thresholds

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Subba Lakshmi

Subba Lakshmi

Full Stack Web Developer | Graduate student of MS in Computer Science at The University of Texas at Rio Grande Valley

More from Medium

Install NVIDIA Driver 510.47.03 on Ubuntu / Linux Mint Via PPA

Buy Tipsonunix a Coffee

Build ns-3 on Docker Ubuntu image on Windows 10/11

Running checkmk with docker-compose behind Traefik

Scripting LCD on Wio Terminal with ArduPy