Pin Me

Setting Up a Linux Samba Server

written by: Kristen Grubb•edited by: J. F. Amprimoz•updated: 7/5/2011

When you have Windows and Linux machines coexisting on the same network, file sharing becomes an issue because each Operating System has its own file system. This is where Samba comes in. Samba runs on Linux and happily shares files and printers between Linux, Windows and Mac.

  • slide 1 of 7

    Why a Samba Server?

    Although Linux will recognize the Windows NTFS file system, the two Operating Systems don't always play nice with one another. If you have a network with both Linux and Windows computers sharing files, it is best to have the correct Samba Linux setup. However, configuring Samba can be a bit of a chore. Previously, Pranav Thadeshwar has shown you how to mount a Windows Share from a Linux Machine and Jack Wallen has shown you how to use Samba to set up a home file server. Now we're going to expand on those two articles and add more users and set up a print server.

  • slide 2 of 7

    The Initial Steps

    First, grab the latest copy of Samba. You can do this through any package manager. For Ubuntu and other Debian based systems, the command is:

    sudo apt-get install samba

    Before you make any changes, stop the service:

    sudo /etc/init.d/samba stop

    Backup the default configuration file:

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

    You can actually just make changes to the smb.conf file, but it is still a good idea to make a backup file anyway. In that case, the command would be:

    sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bkup

  • slide 3 of 7

    Creating the smb.conf file

    Here is a sample smb.conf file that you can copy and paste into your editor:

    [global]

    workgroup = WORKGROUP

    netbios name = MYNAME

    security = user

    null passwords = true

    username map = /etc/samba/smbusers

    hostname lookups = yes

    hosts equiv = /etc/hosts

    hosts allow = 192.168.0.0/255.255.255.0 localhost

    hosts deny = All

    interfaces = lo eth0

    bind interfaces only = yes

    guest ok = yes

    printing = CUPS

    printcap name = CUPS

    [printers]

    comment = All Printers

    browseable = no

    printable = yes

    writable = no

    public = yes

    guest ok = yes

    path = /var/spool/samba

    printer admin = root

    [PhotoSmart]

    comment = HP PSC 1500

    printable = yes

    path = /var/spool/samba

    public = yes

    guest ok = yes

    printer admin = root

    [public]

    path = /home/public

    browseable = yes

    read only = no

    guest ok = yes

    public = yes

    create mode = 766

    [home_directories]

    path = /home/%U

    read only = no

    valid users = %U root

  • slide 4 of 7
    The Samba application allows Linux, Windows and Mac computers to share files, folders and printers. Here we explain Samba file sharing with Windows, the Samba configuration file and how to access your server through Windows.
  • slide 5 of 7

    Explanation of smb.conf

    The following is a breakdown of what is going on in each section:

    [global]

    workgroup = WORKGROUP

    netbios name = MYNAME

    security = user

    null passwords = true

    username map = /etc/samba/smbusers

    hostname lookups = yes

    hosts equiv = /etc/hosts

    hosts allow = 192.168.0.0/255.255.255.0 localhost

    hosts deny = All

    interfaces = lo eth0

    bind interfaces only = yes

    printing = CUPS

    printcap name = CUPS

    load printers = yes

    The workgroup is the name of your Windows Workgroup. It can be found under Start -> Control Panel -> System -> Computer Name.

    The netbios name is the name of the Linux computer. It is how you browse the Linux computer from Windows.

    The next ten lines set up the security for the server. It says that the user will have to log in to the server to access the files, and the only computers that are allowed to see the samba shares are on the home network.

    The two printing variables tell Samba to use the CUPS interface and load the printers automatically.

    [printers]

    comment = All Printers

    browseable = no

    printable = yes

    writable = no

    public = yes

    guest ok = yes

    path = /var/spool/samba

    printer admin = root

    This is the basic set up for all printers. It says that anyone can print but only root can make changes. The next section is the configuration for the actual printer. If you have more than one printer, you will need a section for each one.

    [PhotoSmart]

    comment = HP PSC 1500

    printable = yes

    path = /var/spool/samba

    public = yes

    guest ok = yes

    printer admin = root

    The name between the square brackets "[PhotoSmart]" defines how you will refer to your printer. It is best to pick something relatively descriptive, especially if you have more than one printer.

    The next section sets up a shared file on the Samba server

    [public]

    path = /home/public

    browseable = yes

    read only = no

    guest ok = yes

    public = yes

    create mode = 766

    This section says that any user can view the public folder. Again, the name between the square brackets "[public]" is the share name. Of course, you will have to create this directory with the command:

    mkdir /home/public

    If you want to allow users to access their home directories, you will add the following section:

    [home_directories]

    path = /home/%U

    read only = no

    valid users = %U root

    This allows only the user and root to access the home directory.

    When you are finished making the changes, save the file.

  • slide 6 of 7

    Finalizing the Server Setup

    Test your smb.conf file with the command:

    sudo testparm

    Add your users to the Server:

    useradd -c "New User" -m -g users -p Passwd1 newuser

    The useradd command has the syntax useradd [options] username. The example above has the following options:

    -c is the comments section which is used for the user's Full Name

    -m says to create the user's home directory

    -g is the group name for the user's initial log in group.

    -p is the user's password

    And, let Samba know about the users with the commands:

    sudo smbpasswd -a newuser

    smbpasswd will ask you for a password. You need to supply the password that you use on the Windows machine. If you do not have a password for Windows, just press Enter. (It is always best to have a password for your Windows machine).

    Finally, restart the Samba service:

    /etc/init.d/samba start

    That's it for the Linux part. The hard work is done. Now we just have to let Windows know about the Samba server.

  • slide 7 of 7

    Configuring Windows

    All you have to do in Windows is map the Network Drives by clicking on Start and right clicking My Computer. Select Map Network Drive, choose a drive letter and type \\netbios name\user. This will map a drive to the user's home directory on the Linux machine.

    You can also browse the shared network by choosing Network Neighborhood and clicking on the name of your Workgroup.

    Once you have the network drives mapped, you are done. Enjoy your new Samba Linux setup and network.