How to create a Samba share on Ubuntu Server 20.04

How to create a Samba share on Ubuntu Server 20.04

If you need to share files from Linux, Jack Wallen shows you how simple it is with Samba and Ubuntu Server 20.04.

sambahero.jpg

Image: Jack Wallen

More about Networking

Samba is one of the many ways to share files and directories across a network on Linux. With a Samba share up and running, any machine within your LAN can access the contents of the shared directory–so long as the user has access. Samba also happens to be one of the easiest to set up for this task. 

I want to walk you through the process of installing and configuring Samba on Ubuntu Server 20.04. With this taken care of, your end users will have easy access to anything you want to share out from that server.

SEE: Linux service control commands (TechRepublic Premium)

What you’ll need

  • A running, updated instance of Ubuntu Server

  • A user with sudo privileges

  • Some data to share

How to install Samba

The first thing to be done is the installation of Samba. To do this, log in to your Ubuntu Server instance and issue the command:

sudo apt-get install samba -y

Once the software is installed, you’re ready to configure your first share.

How to configure a Samba share

Because we’re on a GUI-less server, we’ll be taking care of the configuration via the terminal window. Your Samba shares will be configured in /etc/samba/smb.conf, so open that file with the command:

sudo nano /etc/samba/smb.conf

The first option we’ll configure is the workgroup name. Look for the line:

workgroup =

Change that to:

workgroup = WORKGROUPNAME

Where WORKGROUPNAME is the name of the workgroup or NT-domain your Samba server will exist within.

Samba no longer requires you to configure security levels as it once did (such as security = user). The remaining part of the configuration is adding the share at the bottom of the smb.conf file. 

Let’s say you want to use the directory /data that will belong to the group editors containing a number of users. Let’s take care of that first.

Create the new directory with the command:

sudo mkdir /data

Create the group:

sudo newgrp editors

Add yourself to the group:

sudo usermod -aG editors $USER

You can add as many users as you need by replacing $USER with the username to be added. 

Change the ownership of the directory with the command:

sudo chgrp -R editors: /data

Give the group read and write permission to the new directory with the command:

sudo chmod -R g+rw /data

You’re now ready to create the share. 

Back at the /etc/smb.conf file, scroll to the bottom and add the following:

[DATA]
path = /data
valid users = @editors browsable = yes
writable = yes
read only = no

The configuration is simple:

  • [DATA] the visible name of the share

  • valid users = a group that can access the share. Even if a user has been added to Samba (with the smbpasswd command) they will not be able to access this share unless they are a member of the listed group

  • path – the exact path of the share

  • browsable – makes the share visible to the network

  • writable – makes the share writable to authenticated users

  • read only – sets the read-only option to no

Save and close the file. 

Restart Samba with the command:

sudo systemctl restart smbd

How to add a user to Samba

Now that everything’s set up, you must also add users to Samba, otherwise they won’t be able to authenticate. Even though a user has a legit account on the server, until they’re added to Samba, it’s a no-go.

The first thing we have to do is add the user to Samba with the command:

sudo smbpasswd -a USER

Where USER is the user to be added.

You’ll be prompted to type and verify a password for the user.

Next, enable the user with the command:

sudo smbpasswd -e USER

Where USER is the user to be enabled.

How to connect to the new share

How you connect to the Samba share will depend on the operating system in use. I’m only going to demonstrate how to connect to the share from the GNOME desktop on Linux. To do this, open the file manager and click Other Locations at the bottom of the left pane. At the bottom of the file manager window type the following in the Enter Server Address bar:

smb://SERVER​

Where SERVER is the IP address of the server. You’ll then be prompted to click on the share you wish to access, at which point you’ll click DATA. In the resulting popup, select Registered User, type the user name and the password for the user (Figure A).

Figure A

Authenticating to the new Samba share.

” data-credit rel=”noopener noreferrer nofollow”>sambaa.jpg

Authenticating to the new Samba share.

Click Connect and the file manager will open to the share, where you can start working with the files contained within.

Congratulations, you’ve just created your first Samba share on Ubuntu 20.04.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.

Also see

Source of Article