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.

Photo
- - - - -

A Simple Beginners Guide to Setting up a Samba Share


  • Please log in to reply
No replies to this topic

#1 Naught McNoone

Naught McNoone

  • Members
  • 307 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:The Great White North
  • Local time:10:33 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.

Preparation

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 /home/Shares user:user

 

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!

 

 

 

Instructions

  • 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.

 

[printers]

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.

 

[print$]

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:

#[printers]

# comment = All Printers

# browseable = no

# path = /var/spool/samba

# printable = yes

# guest ok = no

# read only = yes

# create mask = 0700

 

#[print$]

# 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:

 

[Shares]

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.

Server role: ROLE_STANDALONE

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.

 

[global]

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

 

[printers]

comment = All Printers

path = /var/spool/samba

create mask = 0700

printable = Yes

print ok = Yes

browseable = No

 

[print$]

comment = Printer Drivers

path = /var/lib/samba/printers

 

[Shares]

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.
 

Summary

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 = 192.168.0.1/255.255.255.128

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

  • 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.

http://www.bleepingcomputer.com/forums/f/11/linux-unix/

My self or someone else will give you assistance.

Cheers!

Naught McNoone.

 



BC AdBot (Login to Remove)

 





5 user(s) are reading this topic

0 members, 5 guests, 0 anonymous users