Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

- - - - -

A Simple Beginners Guide to Setting up a Samba Share

  • Please log in to reply
2 replies to this topic

#1 Naught McNoone

Naught McNoone

  • Members
  • 308 posts
  • Gender:Male
  • Location:The Great White North
  • Local time:04:17 PM

Posted 06 December 2015 - 09:13 PM

A Simple Beginners Guide to Setting up a Samba Share

Guide Overview
The purpose of this guide is to teach novice Linux users how to set up a samba share on their home network, so that they can share files with other computers.
It is meant to augment the tutorial in Linux How-To and Tutorial Section Started by NickAu, 05 Feb 2015. This tutorial primarily uses the terminal to configure samba.
What is samba?
Samba is a suite of programs, that allow Linux based machines to interface with Windows machines in the same network. Samba is licensed under the GNU Public License, and is open to anyone to use.
For more information you can visit samba.org.
Tools Needed

  • A fully functioning Linux installation. This tutorial was completed on Mint 17.2, but should work on any Linux based system.

  • Another computer, using either Windows or Linux, in the same local network. For the purpose of this tutorial, both computers should be on the same sub net.

  • The samba software installed on all the Linux computers used.
1. Make sure that samba is installed on your system.
From your desktop, open a terminal. You can do this from the menu, or use <ctl>+<alt>+<t>.
Type the following command samba -V, and then press enter. Do not type the quotation marks, and remember to leave a space before the dash. Also, it is an UPPER CASE V. Lower case v will not work.

user@system ~ $ samba -V

You should see a line similar to this, in your terminal:

Version 4.1.6-Ubuntu

If you get command not found, or another indicator saying that samba is not installed, you will have to install it.  Install samba by entering this command:

sudo apt-get install samba

Answer yes to install the samba suite.
2. Create something to share.
You can share any directory you want. For our purposes, we are going to create a subdirectory in our /home directory called Shares. Don't forget that Linux is case sensitive!
Do this by entering the following:

sudo mkdir /home/Shares

Next, we must give control of that directory to yourself. You want to change ownership from root to your username.  Do this by entering the following:

chown user:user /home/Shares

Remember to substitute your user name for user, or it will not work!
We now have ownership of our shared files directory, and we can place anything in there we want. For now, let's just copy a file that we will need for samba.
Enter the following commands in your terminal:

cd /home/Shares

cp /etc/samba/smb.conf .

This changes our woring directory to /home/Shares and copies the smb.conf file to that directory. Don't forget, the trailing space and dot tells cp to copy the file to the directory you are in!
OK! We are ready to start working with samba!

  • Step1 Edit your smb.conf file.
Open the copy of the smb.conf file you have in your Shares directory using your text editor. You can use the GUI. I prefer the terminal editor nano.  This file has a lot of information in it already. Even though it looks intimidating, it is fairly self explanatory.
We are going to leave this file mostly the way it is. It is generally set up to use samba defaults, and you don't need to change anything else at this time. Have a look at this setting, for example, near the beginning.

# Change this to the workgroup/NT-domain name your Samba server will part of

workgroup = WORKGROUP

This line instructs samba to tell any Windows computers that you are part of WORKGROUP. If you have a different workgroup in your network, then you should change it to match that. Some older systems may be using MS-HOME. If you are not sure, leave it alone.

HINT: Right click on My Computer in your Windows computer and select the Properties item from the menu. Near the bottom of that page you will find the name of the workgroup you are a member of.

Let's get to the actual share part, near the end of the file. Scroll down until you reach this line:

#======================= Share Definitions =======================

After this line, you will see several samples of different types of shares. Lets look at the sample printer shares. There are two of them. By default, they are both uncommented out.
The first one is the actual printer share it's self.


comment = All Printers

browseable = no

path = /var/spool/samba

printable = yes

guest ok = no

read only = yes

create mask = 0700

The second one shares the directory where you can put your printer drivers, so Windows can install them through the network.


comment = Printer Drivers

path = /var/lib/samba/printers

browseable = yes

read only = yes

guest ok = no

You can leave these as they are, and you will be able to share your printer. If you do not want to share your printer, you can comment them out. Do that by adding a # symbol to the beginning of each line, like this:


# comment = All Printers

# browseable = no

# path = /var/spool/samba

# printable = yes

# guest ok = no

# read only = yes

# create mask = 0700


# comment = Printer Drivers

# path = /var/lib/samba/printers

# browseable = yes

# read only = yes

# guest ok = no

Doing this will prevent samba from sharing your printer.
Lets add our simple share to the smb.conf file.
Here is what is should look like:


comment = Shared Files

path = /home/Shares

browsable = yes

read only = no

The label, [Shares] will show up in your Windows computer network browser as Shares.
Remember, the path has to be the actual path and is case sensitive in Linux.
browsable = yes instructs samba to allow this share to be displayed on the client network browser.
read only = no instructs samba to allow you to modify or copy files to the directory, from a Windows computer.
Once you have added the share to the smb.conf file, you can save and exit the file.
We now have to copy the file back to our /etc/samba folder. Remember that root is the only one who can do this. So we use sudo, again.
We also want to keep a copy of our original smb.conf file, for future referance.
Type the following commands:

sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.original

sudo cp /home/Share/smb.conf /etc/samba/smb.conf

This will back up your original smb.conf file, and tranfer the modified one in it's place.
We are not done yet!

  • Step2 Testing and re-starting the samba server.
We now have our modified smb.conf file in place, but the samba server is still using the old one.
Let's start by testing our file, to make sure it works.
We do this with the following command:

sudo testparm

testparm will load the smb.conf file, and check it for errors. It will advise you of any problems with the file.

Load smb config files from /etc/samba/smb.conf

rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)

Processing section "[printers]"

Processing section "[print$]"

Processing section "[Shares]"

Loaded services file OK.


Press enter to see a dump of your service definitions

It will then prompt you to press enter to display a list of the active lines in your smb.conf file.


server role = standalone server

map to guest = Bad User

obey pam restrictions = Yes

pam password change = Yes

passwd program = /usr/bin/passwd %u

passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .

unix password sync = Yes

syslog = 0

log file = /var/log/samba/log.%m

max log size = 1000

dns proxy = No

usershare allow guests = Yes

panic action = /usr/share/samba/panic-action %d

idmap config * : backend = tdb


comment = All Printers

path = /var/spool/samba

create mask = 0700

printable = Yes

print ok = Yes

browseable = No


comment = Printer Drivers

path = /var/lib/samba/printers


comment = Shared Files

path = /home/Shares

browsable = yes

read only = no

We can now restart the samba server. The simplest way is this:

sudo smbd stop

followed by:

sudo smbd start

or you can try this:

sudo service smbd restart

Both should do the same job!
OK! We are almost there! We now have a functioning samba server, but no one can log on yet!

  • Step3 Setting the samba user's password
Samba needs to know which users are allowed in from Windows. To do that, you must create a samba user, and give them a password.
I our case, we are going to use your user name, because the share belongs to you! (Remember, you gave yourself ownership of it.)  Enter the following command:

smbpasswd -a username

Remember to subsitute your actual username.  You will be prompted to enter the password twice.

New SMB password:

Retype new SMB password:

Added user username.

Now, when you click on the share in your Windows machine, you will be prompted to supply the user name and password.
We now have a simple working samba share, usable by any Windows or Linux computer in your home network.
Before you post a question here, check out the documentation for your specific distro. There are lots of tips and tricks to enhance your samba share.
Ubuntu users can look here: https://help.ubuntu.com/community/Samba
Mint users can look here: http://community.linuxmint.com/tutorial/view/1861
Or just Google linux samba.
Here is a list of things you may want to do:

  • Create multiple shares, listing each one under it's own label. For example, I have individual shares for my general files, movies, music, &c.

  • You can enhance security. Right now, anyone with your username and password can access your share.  I added the following line to my [Global] section:
    hosts deny =

This locks out anyone with an IP address between and, effectively denying my shares to house guests' smart phones. This is because my dhcp server uses the range to

  • Create a user just for the purpose of sharing files. They can be an ordinary user, without admin privileges. This will keep your username and password from being used by everyone!

  • Give each user their own share, with their own password. (Note: They have to have a user name assigned to them on the Linux server!)
If you do get stumped, and can't find the answer on line, post a question in the Linux forum.
My self or someone else will give you assistance.
Naught McNoone.

Edited by Al1000, 06 July 2018 - 04:33 AM.
fixed command discussed in topic below

BC AdBot (Login to Remove)


#2 ksharp117


  • Members
  • 3 posts
  • Local time:02:17 PM

Posted 06 July 2018 - 02:01 AM

I'm trying to fallow this tutorial. I"m having trouble with step 2, changing the ownership of the Shared file from root to user. I'm typing in

chown /home/Shares pi:pi but I keep getting "chown: invalid user: '/home/Shares'


I'm not sure what I'm doing wrong, still pretty new to this. any help would be greatly appreciated.



Sorry, just saw the link. I'll through this up on the linux forum as well.

Edited by ksharp117, 06 July 2018 - 02:12 AM.

#3 Al1000


  • Global Moderator
  • 7,979 posts
  • Gender:Male
  • Location:Scotland
  • Local time:09:17 PM

Posted 06 July 2018 - 04:24 AM

Thanks for starting the new topic. Please continue discussion here:

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users