Installing Samba for Ubuntu
To install Samba from the command line:
$ sudo apt-get install samba
Configuring Samba
The configuration file for Samba is located in /etc/samba/smb.conf. A simple configuration is listed below:
[global]
# Change this to the workgroup name your Samba server will be part of
workgroup = WORKGROUP
# server string is the equivalent of the NT Description field
server string = %h server (Samba, Ubuntu)
# This will require a Unix account in this server for every user accessing the server.
security = user
# The Unix account smbd uses this parameter when a connection is allowed guest access.
guest account = nobody
# Determine whether a failed authentication request should be treated as the guest user and allowed access.
# Use the guest account if the username is unknown to Samba's list of accounts.
map to guest = bad user
# Enable the default home directory shares.
# This will share each user's home directory as \\server\username
[homes]
comment = Home Directories
# Make sure that only “username” can connect to \\server\username
valid user = %S
# By default, the home directories are exported read-only. Change next
# parameter to ‘yes’ if you want to be able to write to them.
writable = yes
# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
create mask = 0600
# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
directory mask = 0700
# Here is one file share named [public], which makes the /tmp directory available for users
[public]
# Specifies whether a user mapped to the guest account is allowed access to this share.
guest ok = yes
# Automatically maps the user to the guest account for access to this share.
guest only = yes
path = /tmp
read only = no
Configuring Samba Authentication
$ sudo smbpasswd -a <username>
Password:
New SMB password:
Retype new SMB password:
The first password is for the sudo application, and the second two are for the Samba password for the <username>.
Configuring Firestarter Firewall
If you have a firewall on the same server as Samba the the rules will need to change to in order for Samba to work.
For Firestarter:
- System -> Administration -> Firestarter
- Click on the “Policy” tab
- Click on the “Allow service” table
- Click on the “Policy” menu -> “Add Rule”
- Under the “Name” dropdown, select “Samba (SMB)” and ports 137-139, and 445 will be populated
- If you want to restrict to only allow computers to your local network then add 192.168.x.x/24 to the “IP, host or network” textbox
- Click the “Add” button to add the policy to Firestarter
- Click on the “Edit” menu -> “Preferences”
- Expand “Firewall” -> “Advanced Options”
- Under the “Broadcast traffic” section, uncheck the “Block broadcasts from external network” checkbox
Reinstalling Samba
When attempting to reinstall Samba after it it has been uninstalled will result in an error.
$ apt-get remove --purge samba
Removing samba ...
* Stopping Samba daemons...
...done.
Purging configuration files for samba ...
Removing configuration file /etc/default/samba...
Removing configuration file /etc/default/samba...
$ apt-get install samba
Setting up samba (3.0.22-1ubuntu3.3) ...
* Starting Samba daemons...
...fail!
invoke-rc.d: initscript samba, action "start" failed.
The reason is because during the uninstallation the /etc/samba/smb.conf file has also been deleted which is required by the samba-common package. To resolve this problem the samba-common package must be resintalled before installing the samba package again.