Create a Samba File Server with Ubuntu or Debian

Setting up a Samba File Server from the command line may sound daunting but in this guide I’ll break it down in to simple steps any beginner with Linux can follow!

You’ll need:

  1. A computer running Ubuntu Minimal/Server or Debian
  2. A computer to be the client (preferably Windows)


Installing Samba

Connect to your Server through SSH or type the commands in to it directly. I’ll be executing all commands as root user. You can change to root with these commands:

Ubuntu:

sudo -i

Debian:

su

The first step is to install Samba on the server.

Ubuntu/Debian:

apt install samba -y

Adding Users

You can add users easily with a single command. The -m creates a home folder for them that makes sharing convenient.

useradd -m john

You’ll also need to add a Samba password for the user.

smbpasswd -a john

Creating Shares

Create a Backup of the smb.conf

cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

Create the folder you intend to share and change ownership to the user who will have access. Replace my name with the users name.

mkdir /home/john/Share
chown -R john /home/john/Share/

Open the Samba configuration file in your text editor of choice and we can begin editing!

vim /etc/samba/smb.conf

If needed, change the workgroup to your desired name

workgroup = WORKGROUPNAMEHERE

Go to the bottom of the page and we can add the share.

[TestShare]
path = /home/john/Share
browsable = yes
valid users = john
writable = yes

You’ll need to restart the Samba service before you can access the share.

/etc/init.d/samba restart

Accessing the Shares

We can now try to access the shares. Get your servers host name or IP access and type it in to windows file explorer beginning with \\. Here are examples however names or IPs will differ.

\\ubuntu-xeon

Or

\\192.16.1.50

Alternatively you can click on “Network” on the left of the file explorer and it should show up. Click on the server and shares you’ve created will show up. You can click on them and enter your username and password

You can only access 1 user at a time per server. So if Bob and John both have a share on a server and you log in as Bob then you can only access Bob’s shares and trying to access John’s won’t work even with the right username and password. A restart will allow you to change users as long as you haven’t asked windows to remember your credentials.

Share this post

This Post Has 3 Comments

  1. Marian

    Create a Backup of the smb.conf

    mv /etc/samba/smb.conf /etc/samba/smb.conf.bak

    and then…

    Open the Samba configuration file in your text editor of choice and we can begin editing!

    vim /etc/samba/smb.conf

    Which is no longer there because you MoVed it.
    so you meant ‘cp’ instead of ‘mv’. Handy hmm, this allergy for complete words?
    This is why linux is impossible for noobs. (Regardless of that the Church of Linux preaches)

    1. John Keen

      Thank you for pointing that out, I corrected it.

      1. Marian

        Thank you. =)
        And thank you for the instructions. I still can’t get it to work. Probably my commandline allergy. Or flat out linux allergy.

Leave a Reply