easy samba setup _ linux

4
Home News Linux Community Learn Linux Directory Jobs Home Learn Linux Linux Tutorials Easy Samba Setup Easy Samba Setup 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. 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. Installation 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 samba smbfs. If you are using Fedora that command would be yum install samba smbfs. Once Samba is installed, it is time to start configuring. 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/samba/smb.conf /etc/samba/smb.conf.bak 2. sudo rm /etc/samba/smb.conf 3. sudo touch /etc/samba/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: [global] - This is the section that contains configuration options used in all sections. [share] - This section will define a share name. [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. [global] netbios name = NETBIOS_NAME workgroup = WORKGROUP security = user encrypt passwords = yes smb passwd file = /etc/samba/smbpasswd interfaces = 192.168.1.1/8 Upcoming Training Courses LF342 Linux Network Management 20 Jan » 23 Jan - Virtual DETAILS LF202 Introduction to Linux 27 Jan » 30 Jan - Virtual DETAILS LF320 Linux Kernel Internals and Debugging 03 Feb » 07 Feb - Virtual DETAILS View All Upcoming Courses Tw eets about "@linuxfoundation OR @lf_training OR #linux" Latest Tutorials Everything You Need to Know to Install SteamOS On Your Very Ow n Computer 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 Sign Up For the Linux.com Newsletter Tweet Tuesday, 30 March 2010 00:00 Jack Wallen | Exclusive search linux.com Linux Foundation Training Events Video ¬† ¬† ¬† ¬† ¬†

Upload: mk

Post on 03-Oct-2015

215 views

Category:

Documents


0 download

DESCRIPTION

Easy Samba Setup _ Linux

TRANSCRIPT

  • Home News Linux Community Learn Linux Directory Jobs

    Home Learn Linux Linux Tutorials Easy Samba Setup

    Easy Samba Setup

    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.

    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.

    Installation

    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 samba smbfs. If you are using

    Fedora that command would be yum install samba smbfs. Once Samba is installed, it is time to start

    configuring.

    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/samba/smb.conf /etc/samba/smb.conf.bak

    2. sudo rm /etc/samba/smb.conf

    3. sudo touch /etc/samba/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:

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

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

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

    [global]

    netb ios name = NETBIOS_NAME

    workgroup = WORKGROUP

    security = user

    encrypt passwords = yes

    smb passwd file = /etc/samba/smbpasswd

    interfaces = 192.168.1.1/8

    Upcoming Training Courses

    LF342 Linux Network Management

    20 Jan 23 Jan - Virtual

    DETAILS

    LF202 Introduction to Linux

    27 Jan 30 Jan - Virtual

    DETAILS

    LF320 Linux Kernel Internals and Debugging

    03 Feb 07 Feb - Virtual

    DETAILS

    View All Upcoming Courses

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

    Latest Tutorials

    Everything You Need to Know to Install SteamOS On Your Very

    Ow n Computer

    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

    Sign Up For the Linux.com Newsletter

    Tweet

    Tuesday, 30 March 2010 00:00 Jack Wallen | Exclusive

    search linux.com

    Linux Foundation Training Events Video

  • [SHARE_NAME]

    comment = COMMENT

    path = /PATH/TO/SHARE

    writeable = yes

    create mask = 0770

    force create mode = 0770

    locking = yes

    [printers]

    comment = COMMENT

    path = /var/spool/samba

    guest ok = Yes

    printab le = Yes

    use client driver = Yes

    browseable = 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/samba 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 smbpasswd -L -a USERNAME

    and

    sudo smbpasswd -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/samba

    sudo chmod 777 /var/spool/samba

    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

    WHO WE ARE ?

    The Linux Foundation is a non-profit

    consortium dedicated to the grow th of

    Linux.

    More About the foundation...

    Frequent Questions

    Join / Linux Training / Board

    EXPLORE

    Answ ers

    Blogs

    Forums

    Directory

    STAY CURRENT

    Netbooks

    Cloud Computing

    Enterprise

    Embedded & Mobile

    ABOUT LINUX.COM

    How to Participate

    Contact / About

    Advertise

    Privacy / Terms / Editorial Policy

    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.

    Post Comment

    Comments

    Name :

    Email :

    Comment :

    Subscribe to Comments

    13 Febwajaheth :

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

    Report Reply

    30 Sepusenix :

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

    system.

    Report Reply

    03 DecBill :

    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