Samba Linux: The Open Source File and Print Server

Samba is an open-source software suite that runs on Unix/Linux based platforms but is able to communicate with Windows clients like a native application. So Samba is able to provide this service by using the Common Internet File System (CIFS).

At the heart of this CIFS is the Server Message Block (SMB) protocol.  Samba does this by performing these 4 key things –

Samba can be run on many different platforms including Linux, Unix, OpenVMS and operating systems other than Windows and allows the user to interact with a Windows client or server. It can basically be described as the Standard Windows interoperability suite of programs for Linux and Unix.

How to install Samba Server on Ubuntu?

Let’s take a look at setting up a Samba Server on Ubuntu to share files with Windows clients. Note that we will create two forms of Samba server. One setup won’t require a password to share files with any client on the network, which is the anonymous share. The other setup will require setting up users and permissions.

1. Install Samba

Binary packages of Samba are included in almost any Linux distribution. There are also some packages available at the Samba homepage. In fact there are now several GUI interfaces to Samba available to help with configuration and management. This article will help you install and set up Samba via the Linux terminal.

We install the samba package from the terminal in Ubuntu with the following code –

sudo apt-get update
sudo apt-get install samba

2. Configure File Server – Anonymous Share

a. Create a shared folder called “shared folder”.

sudo mkdir -p /srv/samba/sharedfolder

b. ​Allow anyone to access and store files in folder.

sudo chown nobody:nogroup /srv/samba/sharedfolder/

c. Edit configuration file to enable sharing.​

Make a backup of the configuration file before editing

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old

Open the conf file and make the following changes –

sudo vi /etc/samba/smb.conf

Add the following at the end of the file to enable sharing – d. Restart smbd service –

sudo systemctl restart smbd.service nmbd.service

3. Configure File Server – Secured Share

a. ​Create shared folder called “securedfolder”.

sudo mkdir -p /srv/samba/securedfolder

b. ​Create a new user group named “selected”.

sudo addgroup selected

c. ​Modify permission and ownership for the folder.

sudo chown root:selected /srv/samba/securedfolder/
sudo chmod 770 /srv/samba/securedfolder/

d. Edit configuration file to allow sharing

​Make a backup of the configuration file before editing.

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old

Open the conf file and make the following changes –

sudo vi /etc/samba/smb.conf

Add the following at the end of the file to enable sharing –

[sharedfolder]
comment = secured shared folder
path = /srv/samba/securedfolder
Valid users = @selected
guest ok = no
writable = yes
browsable = yes

e. Restart smbd service –

sudo systemctl restart smbd.service nmbd.service

f. ​Once Samba has restarted, use this command to check your smb.conf for any syntax errors. testparm g. Add new users

​We are going to create and add a user “Jack” to the user group “selected” with restricted shell access. sudo useradd jack -s /usr/sbin/nologin -G selected To add a password for the user –

sudo smbpasswd -a jack

h. Add existing user Jane to the group to the group “selected”.

sudo usermod jane -G selected

Conclusion

You should be able to access and browse files from these servers from your Windows client. If you do not see your client automatically, you can try accessing it via its IP address.

You can access the Ubuntu sharing in Windows by entering “\\sharedfolder” or “\\securedfolder” in the windows search field of the menu or use the network browser of the Windows file explorer to connect to the share.

In the case of the secured share, the user will be required to enter the password before being able to access the shared folder. And there it is folks, a short guide to setting up samba server on Ubuntu. You can also check out the official how-to to find out more about installing and setting up Samba. ​

SHARE THIS POST

MassiveGRID Banner
4 Comments Text
  • Pff as usual on Linux ; a massive pain to do anything and now even the online help is helpless as this one literally miss a chunk of configuration lines

  • Leave a Reply

    Your email address will not be published. Required fields are marked *