Yin and Yang

CHARLES AUER (dot) NET

Installing Samba 3 on Ubuntu

This tutorial should work on any distro based on Debian, but I have only tested it on Ubuntu 12.04.2.
You will need to run the commands as root or via sudo, which is the prefered method for Ubuntu.

Installing

You would normally use Samba when you are serving files to Windows-based computers. For Linux or OSX machines, there are better/easier ways to share files like Network File System (NFS).

This tutorial will be setting up classic Samba shares in a standalone role. This tutorial is using Samba 3 as that is the version I have installed on my server.

You will need to run this command in a terminal to ensure you have an updated list of available packages as well as install the samba packages (You can copy/paste the command if you wish):

sudo apt-get update && sudo apt-get install samba

The installation of Samba will begin after you confirm. After the installation is complete, you will be back to a shell prompt.

You may be prompted to configure Samba, where it will prompt for the workgroup name, do so and hit enter.

Do not forget to allow TCP ports 139 and 445 as well as UDP ports 137 and 138 through your firewall.

Configuring

Once the installation is complete, you should be able to see your new samba server on the network, providing you have something set up to provide name resolution. I use DNSMasq for local name resolution, and it works very well on a small network.

In order to access the shares on your new samba server, you must create samba users and set samba passwords for each of them.

Note: You need to have a local user in order to add a local samba user using the following method.

You can create a local user by using the adduser command like so:

sudo adduser username

In order to create a local samba user, you need to run the following command: Replace username with the username of the account you want to set a password for.

sudo smbpasswd -a username

Now that you have a user that can access the samba server, you can configure your shares. In order to do this you must add your share definitions to /etc/samba/smb.conf - you can do this with nano, or whatever text editor you prefer, or even use something like Webmin or Zentyal. Those are just a couple of the GUI tools around, you can find a list of some more of them at samba.org.

You can find a full list of parameters at samba.org.

Here is a list of some of the valid settings for the share definitions:

Samba Share Parameters with Syntax
Parameter Description Syntax
browseable Defines if the share is shown or not.
Default is yes.
browseable = yes | no
hide dot files Hide or show hidden files (those starting with a dot)
Default is yes.
hide dot files = yes | no
path The path to the folder you want to share. path = /path/to/folder
create mask Default is 0664. create mask = 0664
directory mask Default is 0775 directory mask = 0775
force group Changes the default group for all users connected to the share.
Disabled by default.
force group = group
force user Changes the default user for all users connecting to the share.
Disabled by default.
force user = username
guest ok Allows guest access.
Default is no.
guest ok = yes | no
valid users Which users are allowed to connect to the share.
All users are allowed by default.
valid users = username, @group
invalid users Which users are not allowed to connect to the share.
All users are allowed by default.
invalid users = username, @group
read only Makes a share read only.
The default is yes.
read only = yes | no
writeable Makes a share read/write.
The default is no.
writeable = yes | no
read list List of users or groups that are only allowed read access to a share.
It is not used by default.
read list = username, @group
write list List of users or groups that are only allowed write access to a share.
It is not used by default.
write list = username, @group

Here is what one of my share definitions looks like:

[Charles]
        invalid users = htpc
        create mask = 660
        path = /media/data/charles
        write list = charles
        directory mask = 770

Whenever you make a change to smb.conf, be sure to run testparm to ensure that there are no syntax errors in your smb.conf file.

testparm -s /etc/samba/smb.conf

If you make a change to smb.conf, you will also have to restart the services that Samba uses (smbd and nmbd) for the changes to take effect.

sudo service smbd restart
sudo service nmbd restart

Once you have your share definitions set up, you will be good to go.