Está en la página 1de 4

Linux Foundation

Training

Events

Video

search linux.com

Home

News

Home

Linux Community

Learn Linux

Learn Linux

Linux Tutorials

Directory

Jobs

Easy Samba Setup

Easy Samba Setup


Tuesday, 30 March 2010 00:00

Jack Wallen

Exclusive

Tweet

If you are either a power home user or you are in a business environment, you know the importance of
machines being able to see one another. Recently I did an article about this very topic ("Sharing Files &
Folders Between Linux, Mac, and Windows") which skimmed this topic, showing how simple it is to allow
these different operating systems to see one another - with the help of Samba. But that article didn't dig
too deeply into Samba itself. That article was more of a "let's see how we can do this quickly and easily"
tutorial.
Upcoming Training Courses
This time around I'll focus more on Samba and how it is installed and configured to allow for the sharing
of files and folders. For this article, we will look at the smb.conf configuration file and how it is set up and
how to create new shares and even share printers. You will be using a text editor and a few commands.
So get your fingers ready to type.

LF342 Linux Netw ork Managem ent

Installation

27 Jan 30 Jan - Virtual

Installing Samba is really quite simple. Since we are going to be dealing with the command line, let's
install Samba in the same way. So open up your favorite terminal window and prepare to install.
All of the installation commands will be issued as either the root use or by using the sudo command
Whether you use su or sudo will depend upon which distribution you are using. If you are using Fedora (or
a Fedora-like distribution), you will su to the root user. If you are using Ubuntu (or a Ubuntu-like
distribution), you will use sudo.
Within the terminal window, issue the command sudo apt-get install samb a smb fs. If you are using
Fedora that command would be yum install samb a smb fs. Once Samba is installed, it is time to start
configuring.

20 Jan 23 Jan - Virtual


DETAILS
LF202 Introduction to Linux
DETAILS
LF320 Linux Kernel Internals and Debugging
03 Feb 07 Feb - Virtual
DETAILS
View All Upcom ing Courses

Tw eets about "@linuxfoundation OR @lf_training OR #linux"

Configuration
There is only one file you need concern yourself with - /etc/samba/smb.conf. Out of the box, this file might
be rather daunting. I always like to start from scratch, so I do the following (from command line):
1. sudo mv /etc/samb a/smb .conf /etc/samb a/smb .conf.b ak
2. sudo rm /etc/samb a/smb .conf
3. sudo touch /etc/samb a/smb .conf
The above simply makes a backup of the smb.conf file, removes the original, and then creates a new,
empty smb.conf file.
Before we actually begin creating our smb.conf file, let's take a look at how this file is structured. The
smb.conf file is broken down in to sections, with each section beginning with [NAME] (Where NAME is the
name of the section). Typical sections are:

Latest Tutorials

[global] - This is the section that contains configuration options used in all sections.

Everything You Need to Know to Install SteamOS On Your Very

[share] - This section will define a share name.

Ow n Computer

[printers] - This section will define a shared printer.


Within each section will be directives that define various aspects of a configuration. Let's take a look at a
minimal (but useful) smb.conf file.
[glob al]
netb ios name = NETBIOS_NAME

Benchmarking the ODroid XU: A Fast-Clocked Quad A15 ARM


Machine
How to Access Tw itter from the Command Line on Linux
Troubleshooting in the Command Line: Tips for Linux Beginners
How to Start a Program Automatically in Linux Desktop

workgroup = WORKGROUP
security = user
encrypt passwords = yes
smb passwd file = /etc/samb a/smb passwd
interfaces = 192.168.1.1/8

Sign Up For the Linux.com Newsletter

[SHARE_NAME]
comment = COMMENT
path = /PATH/TO/SHARE
writeab le = yes
create mask = 0770
force create mode = 0770
locking = yes

[printers]
comment = COMMENT
path = /var/spool/samb a
guest ok = Yes
printab le = Yes
use client driver = Yes
b rowseab le = No
NOTE: Everything in bold is system specific.
There are a few things we must touch on with the above configuration. Let's go line-by-line as needed
(many of the lines should be self-explanatory).
security = user: This line defines the method of authentication Samba will use. I have always found user
to be the most reliable. Samba has five different methods:
user: Each user will have an account on the machine hosting Samba.
server: This mode is not used anymore - it defines an external authentication server.
ADS: Active Directory mode.
Domain: This type is a centrally located account which is shared between domain controllers.
share: Clients will authenticate against a particular share on the Samba server.
interfaces = 192.168.1.1/8: This line will dictate the addresses that are allowed to connect to your shares.
This will be specified by your network topology.
create mask = 0770/force create mode = 0770: These lines dictate the permissions given to anything
created, by users, within the share. In this case the clients will get read/write access to all files except
those belonging to "other." Without these lines, clients will have trouble creating files/folders in the share.
locking = yes: This is critical when sharing folders as it will create a lock file for any open file. When a file
has an associated lock file other users can not open that file for writing. This prevents users from
overwriting changes at the same time, causing file corruption.
use client driver = Yes: This line dictates that Samba is not required to share out drivers for clients. If you
are on a larger network then you might want to share out drivers. Otherwise the drivers for the shared
printer will have to be installed on the client machines.
Once you have that file created, save it and then restart Samba (with a command like sudo
/etc/init.d/samb a restart). Of course you're not done yet.
Adding Users
If you do not add users to your Samba installation, those users will not be able to authenticate, which will
keep them from browing/using the shares. In order to add a user you have to issue two commands:
sudo smb passwd -L -a USERNAME
and
sudo smb passwd -L -e USERNAME
Where USERNAME is the actual username on the system.
The first command will add the user and a password for the user (you will be prompted to enter the new
user password after you enter the command). The second command enables the user for Samba.
Now your users are ready to authenticate and use Samba. You can go back to the original article I
mentioned (at the beginning of this tutorial) to see how to connect to the server from both Mac and
Windows.
Printers
A note about printers. In some instances Samba will not add the /var/spool/samba directory that is used
for printer spooling. Check to see if this exists with the command ls /var/spool/. If you see samba there,
you are good to go. If not, issue the following commands:
sudo mkdir /var/spool/samb a
sudo chmod 777 /var/spool/samb a
That should do it. Make sure the printer you wish to share actually works on the local Linux machine and it
should be shared out and ready to go for your clients.

Latest Software News


The Case for a Compulsory Bug Bounty
Fedora 20 Released
GCC Compiler Receives ARM big.LITTLE Tuning Support
Distribution Release: Zentyal 3.3
Early Ubuntu 14.04 Tests Show Some Performance Changes

Final Thoughts
Samba is not as difficult to set up as most assume. In fact, once you get the hang of it you will find it
easier to share out files and folders with Samba than it is with any other operating system.

Jack Wallen

Comments

wajaheth :

13 Feb

I cant use samba service in linux ? what is the problem

Report

Reply

usenix :

30 Sep

Good article, but the Final Thoughts - samba isa filesystem, not an operating
system.

Report

Reply

Bill :

03 Dec

Jack, You look so nice with your tatoos and your strong muscles. Have you been
working out? How do you have time to write all of these awesome geeky blogs
when you have such an awesome image to maintain? -Will

Report

Reply

Name :

Email :

Comment :

Post Comment

Subscribe to Comments

WHO WE ARE ?

EXPLORE

STAY CURRENT

ABOUT LINUX.COM

The Linux Foundation is a non-profit

Answ ers

Netbooks

How to Participate

Blogs

Cloud Computing

Contact / About

Forums

Enterprise

Advertise

Directory

Embedded & Mobile

Privacy / Terms / Editorial Policy

consortium dedicated to the grow th of


Linux.
More About the foundation...
Frequent Questions
Join / Linux Training / Board

Linux.com 2012 Linux.com. All rights reserved.


The Linux Foundation Symbol is a trademark of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.

También podría gustarte