Installing A Samba Server Computer Science Essay

Published: Last Edited:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

The samba package is a meta-package planned to be installed on servers. Clients do not need this meta-package mainly it uses when we are acting as a client if we need to access files on another computer. As a example, installing samba is not necessary if we only need Ubuntu system to do any of the following:

Access shared folders, drives and printers on a Windows computer. To do this, we only need the smbfs plugin.

Have Windows computer use a printer that is attached to a Linux computer. CUPS can be configured to make the printer accessible to the network.

Share directories between two Linux computers. we can use NFS or setup an server on one computer and access it from other computers using an scp or sftp client.

Nautilus Integration

If we want to be talented to share folders with nautilus the file browser, install the nautilus-share package installed by default in Ubuntu 9.10 Desktop edition:

sudo apt-get install nautilus-share


If we wish our computer to act as a Samba server act as a file or printer server then install the samba package

sudo aptitude install samba


The samba package is not needed on clients. Install smbfs instead

sudo aptitude install smbfs

If we want to connect to a Samba server when Windows server or an Ubuntu server running Samba we have two options, we can use the smbclient command or we can directly mount the samba file system via smbfs.

Command line

Ubuntu will connect to a Samba server out of the box via smbclient. This is a similar to a FTP connection. Once connected, we can use commands such as ls, cd , put, and get.


This package allows clients to mount Samba file shares; agree to them to act as local disks. Most people will prefer this method.

Server Configuration

For Ubuntu new versions, shared folders are created directly from the folder. Browse to the location of the folder we would like to share, right-click the folder, and choose Sharing Options. Click the Share this folder check box, and click Install Services. Enter the password, and the Samba server packages will be downloaded and installed.

Browsing SMB shares

Open the Places Menu, and then click on Network. We will see a Windows network icon. Double-click to open it. The next window shows all the domains/workgroups found on our network. Inside each domain/workgroup we will see all the computers on the domain/workgroup with distribution enabled. Double-click on a computer icon to access its shares and files. Before showing a computer's shares, our system may prompt us for a name and password. Fill in the form by means of the credentials of a valid user for the computer we are connecting to. We may additionally store that password in keyring for convenience. However the default installation of Samba does not synchronize passwords. we may have to run "smbpasswd" for each user that wants to have access to his Ubuntu home directory from Microsoft Windows.

Graphical Configuration

This section is for those rather to use graphical tools. This section should allow us to "quick start" SMB shares between Ubuntu and also Ubuntu or Windows servers. The gui technique is easier to work with, because:

Shares are Public, (which can brows from Network Places)

A password is not set (for shares which can be mounted by anyone).

Be caution we are installing a server and we may wish to install a Firewall administration utility to help prevent undesired access. See also the manual configuration sections below to learn how to "hide" the shares from browsing and set a password for access.

Ubuntu Server

This section enables Ubuntu as a samba file server.

Sharing a Folder

To share a directory we must have permission to access the directory. Go to home directory (Places -> Home folder). Right click on the "Documents" directory and in the pop up menu select "Share Folder". If samba is not installed we will get a pop up menu "Sharing services are not installed". Select "Install Windows networks support (SMB)" and deselect "Install Unix networks support (NFS)" -> then click "Install services". If we get an error message that the samba .deb could not be found, open a terminal and update apt-get.

sudo apt-get update

Try again and Ubuntu will download and install samba. Right click on the "Documents" directory and in the pop up menu select "Share Folder". we will get a pop up menu "Share Folder". Select "Windows networks (SMB)" in the pull down menu and give our share a name in the "Name" box. Unselect the "Read only" check box if we want read/write access to the share. Click the "Share" button.

Windows XP Server

This section enables Windows XP as a samba file server.

Sharing a Folder

1. On the Windows server, browse in explorer ("My Computer") to the location of the folder we wish to share (C:\Documents and Settings for example). Next right click on the folder to share and select "Sharing and Security...". In the pop-up dialog box click the "Sharing" tab. click the "Network Setup Wizard" to configure the network to permit shares. Work with way through the wizard. Note the default workgroup is MSHOME. We may change this value if we like but all our computers should be in the same workgroup. Eventually we will be given the option to "Turn on file and printer sharing". This is the option we want, continue with the network wizard. We will have to restart the computer for the settings to take effect -> Restart Windows.

2. After rebooting, again open explorer ("My Computer") and navigate to the folder we wish to share. Again right click on the folder and select "Sharing and Security..." In the pop-up dialog box click the "Sharing" tab. In the "Network sharing and security" box, tic (select with the mouse) the "Share this folder on the network" box. Give the folder a share name. This will give read only access to Ubuntu computers via samba. To agree to read/write access tic (select with the mouse) the "Allow network users to change my files" box. Click the "Apply" button and close the dialog box.

Connect to a samba server

Configure the Ubuntu or Windows XP samba server as above.

Ubuntu Client

On the Ubuntu client using the menu at the top, go to "Places" -> "Network". We will see an icon "Windows network" and should be able to browse to the shared folder. We will be asked for a password, leave it blank. Click the "Connect button. It also can do with selecting from the menu at the top select "Location" -> "Connect to a server". In the "Service type" pull down select "Windows share". Enter the server IP address in the "Server:" box and the share name in the "Share:" box. Click "Connect" and then "Connect" again on the second dialog box it no need any passwords.

If we would like to mount SMB share using server hostname rather than the IP Address, edit /etc/hosts and add to samba server (syntax IP Address hostname). hostname

Where "hostname" = the name of our samba server.

Windows XP Client

On Windows open "My Computer" and find the way to "My Network Places". Navigate to Ubuntu server and share will be available without a password. It also can do with selecting from the menu at the top select "Tools" -> "Map Network Drive". Select an available letter for our SMB share. In the "Folder:" box enters \\samba_server_ipaddress\share. Put a Tic mark with selecting with the mouse the option "Reconnect at login" if we want the share to be automatically mounted when we boot Windows. Click the "Finish" box. A dialog box will appear, enter the samba user name and password. Click "OK". If we would like to mount your SMB share using our server hostname rather than the IP Address, edit C:\WINDOWS\system32\drivers\etc\hosts and add to our samba server (syntax IP Address hostname). hostname

Where "hostname" = the name of our samba server.

Samba Client Manual Configuration

These sections cover up how to manually configure and connect to a SMB file server from an Ubuntu client. smbclient is a command line tool similar to a ftp connection while smbfs allows us to mount a SMB file share. Once a SMB share is mounted it acts similar to a local hard drive which we can access the SMB share with the file browser.

Connecting to a Samba File Server

Command line

Connecting from the command line is similar to an ftp connection.

List public SMB shares with

smbclient -L //server -U user

Connect to a SMB share with

smbclient //server/share -U user

Enter the user password. we can connect directly with

smbclient //server/share -U user%password

But our password will show on the screen. Then once we connected you will get a prompt that looks like this :

smb: \>

Type "help" , without quotes, at the prompt for a list of available commands.


CIFS is built-in in the smbfs package and is a substitute for smbfs

Allow non-root users to mount SMB shares

By default only root may mount SMB shares on the command line. To permit non-root users to mount SMB shares we could set the SUID, but I advise us to configure sudo. We should configure sudo with visudo we may either permit the gruop "users" to mount SMB shares, or add a group, samba, and add users we wish to allow to mount SMB shares to the samba group.

sudo groupadd samba

sudo adduser user samba

Change "user" to the username we wish to add to the samba group.

sudo visudo

In the "group" section add our group we wish to permit to mount SMB shares

Add a line in the "group" section :

## Members of the admin group may gain root privileges

%admin ALL=(ALL) ALL

%samba ALL=(ALL) /bin/mount,/bin/umount,/sbin/mount.cifs,/sbin/umount.cis

The next will mount the myshare folder on myserver to ~/mnt .it will be also in our home directory

mkdir ~/mnt

sudo mount -t cifs //myserver_ip_address/myshare ~/mnt -o username=samb_user,noexec

The "noexec" option avoids executable scripts running from the SMB share. We will be asked for BOTH our sudo and then our samba user password. To umount,

sudo umount ~/mnt

Auto magically mount SMB shares

In order to have a share mounted automatically every time you reboot, we need to do the following things also

With any editor, create a file containing the Windows/Samba user account details:

gksu gedit /etc/samba/user

KDE users must use kdesu rather than gksu and instead of Gedit they can use Kwrite as editor. it be supposed to hold two lines as go after:



Save the file and exit gedit.

Modify the permissions on the file for security:

sudo chmod 0400 /etc/samba/user # permissions of 0400

= read only

Now create a directory where we want to mount our share (e.g./media/samba share):

sudo mkdir /media/samba_share

Now, using any editor, and add a line to /etc/fstab for our SMB share as follows:

sudo cp /etc/fstab /etc/fstab.bak

gksu gedit /etc/fstab

Add a line for our SMB share:

//myserver_ip_address/myshare /media/samba_share cifs

credentials=/etc/samba/user,noexec 0 0

The share will mount automatically when we boot. The "noexec" option prevents executable scripts running from the SMB share.

To mount the share now, without rebooting,

sudo mount /media/samba_share

We can also unmount the share with:

sudo umount /media/samba_share

If we wish to increase security at the expense of expediency, use this line in /etc/fstab

//myserver_ip_address/myshare /media/samba_share cifs noauto,credentials=/etc/samba/user,noexec 0 0

The noexec" option prevents executable scripts running from the SMB share.

Edit /etc/samba/user, remove the password (leave just the samba user).

Now the share will NOT automatically mount when we boot and we will be asked for our samba password.

Mount the share with :

sudo mount /media/samba_share

CIFS may cause a shutdown error.

CIFS VFS: Server not responding.


When mounting a share on the local file system allows us to work around programs that do not up till now use GnomeVFS to browse remote shares transparently. To mount a SMB share, first install smbfs:

sudo apt-get update

sudo apt-get install smbfs

To allow non root accounts to mount shares, modify the permissions on the smbmnt program thus:

sudo chmod u+s /usr/bin/smbmnt /usr/bin/smbumount

The working line in /etc/sudoers is as pursue (see CIFS section above):

%samba ALL=(ALL) /bin/mount,/bin/umount,/sbin/mount.cifs,/sbin/umount.cif


This allows any user in the samba group to mount SMB shares. To this we will need to create a samba group and add users.

The following will mount the myshare folder on myserver to ~/mnt

mkdir ~/mnt

smbmount //myserver/myshare ~/mnt

To umount,

smbumount ~/mnt

In order to have a share mounted automatically every time we reboot, we need to do the following:

Open a shell as root

sudo -s

Create a file containing your Windows/Samba user account details:

vi /etc/samba/user

It should contain as follows:

Change the permissions on the file for security:

chmod 0600 /etc/samba/user

Now create a directory where we need to mount our share (e.g. /mnt/data):

mkdir /mnt/data

Now edit the file system table (/etc/fstab) and add a line as follows:

//server/share /mnt/data smbfs

credentials=/etc/samba/user,rw,uid=bob 0 0

Where 'bob' is the non-root user we log into ubuntu with, 'server' is the name or address of the Windows device and 'share' is the name of the share. To mount the share now, just use the following command as root. It will mount automatically on subsequent reboots.

mount /mnt/data

Samba Server Manual Configuration

Configuration is performed by reading and editing /etc/samba/smb.conf, the configuration file for the samba server. There are a few graphical tools available such as "kdenetwork-filesharing" and "Swat". A fairly comprehensive graphical Samba configuration tool is available for KDE, by installing the "kdenetwork-filesharing" package. Once install, we can find it by launching the KDE Control Center. (Alt-F2 and then type kcontrol). Browse to Internet & Network > Samba. It is fairly easy to use.

The following tips show how to do some basic things without installing additional software, using the command line. It is not difficult, just be careful with typos. First open a terminal: Applications > System Tools > Terminal and open the file smb.conf

sudo nano -w /etc/samba/smb.conf

How to Save: To save in nano use "CTRL-O", then "CTRL-X".

Tip: Replacing nano with gedit gives us a nice graphical editor.

The file *smb.conf* is divided in several sections:

Global Settings




File sharing


Share Definitions

Global Settings

Let's start with Global Settings. It will see several lines, which we can also see in the graphical network tool like workgroup and wins server. If we changed everything to our liking already then we can skip this section, if not change to what we need. If we do not know what items mean,. It will save our trouble-shooting later.

File Sharing (Basics)

The important part for us is File sharing. Samba shares are named in brackets, [ ], and configured by adding options in the lines that follow. Most options are boolean. It means there are two options with "yes" and "no"

We have to change:


comment = Home Directories

browseable = no

# By default, the home directories are exported read-only.

Change next

# parameter to 'yes' if we want to be able to write to them.

writable = no

This describes our /home folder. Usually we want to share this folder in a home-environment, because these are the files we want to share. To do so, make the following changes:


comment = Home Directories

browseable = yes

# By default, the home directories are exported read-only.

Change next

# parameter to 'yes' if we want to be able to write to them.

writable = yes

This finishes sharing the folder. The last thing we need to do is fixing a user.

Add users who can access our shares with the 'smbpasswd' command.

sudo smbpasswd -a username

New SMB password:

Retype new SMB password:

Added user username.

The username used here should be a real user setup on our PC/Server. Reload Samba for every change to users/passwords or 'smb.conf'

sudo /etc/init.d/samba reload

File Sharing (Advanced)

We started with the base of Samba file-sharing. The above-mentioned items should be enough to get you started. Next we will add details that you might or might not need.

If we have more than one network card

If we have more than one network card then we have to define where we want Samba to run. In smb.conf under the [global] section, add:

interfaces =,

bind interfaces only = yes

The first address (, is a loopback network connection (it's our own machine). The second address (, is the address of the card we want Samba to run on, the second number (24) is the subnet default for a CLASS-C network. It may vary depending on the network.

With "bind interfaces only" we limit which interfaces on a machine will serve SMB requests.

We can limit which IP address can connect to our Samba server adding these lines:

hosts allow =,,

hosts deny =

The loopback address must be present in the first line. The second line deny access from all IP address not in the first line.

Private and public shares in same config

First we'll want to set this up in the [global] section of our smb.conf


security = user

encrypt passwords = true

map to guest = bad user

guest account = nobody

security = user restricts logins to users on the server. encrypt passwords = true is necessary for most modern versions of Windows to login to shares. map to guest = bad user will map login attempts with bad user names to the guest account we specify with guest account = nobody. That is, if we attempt to login to the share with a user name not set up with smbpasswd the we will be logged in as the user

Next the private share


comment = Private Share

path = /path/to/share/point

browseable = no

read only = no

If browsable is set to no the share will not show up on graphical browsers such a "My Network Places" on Windows or Places -> Network on Ubuntu.

Path is the path to the directory that we need to share out. browseable = no will have the share not show up when users browse the network. read only = no will let we, as an authenticated user, write to the share.

Finally, the public share


comment = Public Share

path = /path/to/share/point

read only = no

guest only = yes

guest ok = yes

Again, path is the path to the directory that we want to share out. read only = no will allow users to write to this share. guest only = yes and guest ok = yes will allow guest logins and also force users to login as guests. The user you specified with guest account in the [global] section must have write permissions on /path/to/share/point in order to write files to the share.

At what time Windows attempts to access a SMB share it will use the current Windows user name and password. The map to guest = bad user trick above permit access to the public share only if you give Samba an incorrect user name. If you give it a valid user name, but a bad password, the login will fail and Windows will give us a password prompt when you try to access the share. If you have the same user name for our Windows machine and our Ubuntu machine, we could be unwittingly giving the Samba server a valid user name, but invalid password. To resolve this we will either have to change the Windows user name, or to remove that user name from the Samba password file with sudo smbpasswd -x [username].

The above uses security = user. To access the private shares you will have to make sure the user exists in smbpasswd. These users must also already exist as normal users on your machine. You add users to smbpasswd simply by running sudo smbpasswd -a [username] and giving a password.

Setting permissions

To set permissions of newly created documents / files edit /etc/samba/smb.conf and in the [global] section add :

create mask = 0644

directory mask = 0755

Sharing CUPS Printers

Graphical Configuration

Setup Ubuntu Print Server

In your menu go to System -> Administration -> Printing

Under "Local Printers" on the left, select the printer you wish to share. Select the "Policies" tab on the right and make sure the "Shared" box is selected.

Ubuntu Client

Again go to System -> Administration -> Printing

Click "New Printer" in the upper right. In the next menu select "Windows Printer via SAMBA". Now enter your Ubuntu Samba Print Server (set up as above) IP address in the box on the left titled "smb://". Click the "Browse" button.

Select the printer in the "SMB Browser" window (Click on the little arrows). Once you have selected your printer, check the "Authentication required" and enter your samba user name and password. Then click the "Verify" button. You should see confirmation that the share is available.

Click the "Forward" button and install the drivers for your printer as you would for any other printer.

Windows Client

Go to Control Panel -> Printers

Click "Add a printer" on the upper left. The printer wizard will start -> click forward. Select Network Printer and click "Next". Select "Browse for a printer" (Top button) and click "Next". In the next window, navigate to your Ubuntu Samba Print Server and click "Next". Continue with the printer and driver installation.

Manual Server Configuration

If You would like to share Your printers make the following changes to Samba:

If not already done create the Samba-user You want the share to be used by.

In smb.conf uncomment and change the lines ending up with the following configuration:

########## Printing ##########

# If you want to automatically load your printer list rather

# than setting them up individually then you'll need this

load printers = yes

# [...] // Some BSD printing stuff, do not edit if You do not need to

# CUPS printing. See also the cupsaddsmb(8) manpage in the

# cupsys-client package.

printing = cups

printcap name = cups

and in the Share Definitions section append and/or modify the [printers] part ending up like this:

# ======================= Share Definitions =======================

# [...] // File and Folder sharing, do not edit if You do not need to


comment = All Printers

browseable = no

path = /tmp

printable = yes

public = yes

writable = no

create mode = 0700

printcap name = /etc/printcap

print command = /usr/bin/lpr -P%p -r %s

printing = cups

Some explanation what is done:

the [printers] part defines the default-behavior for all the printers that are mentioned in "printcap name". A sort of template how to create shares for these printers. This template is applied if "load printers" is set to true. For more detailed explanation refer to the Samba documentation.

And do not forget to reload Samba:

sudo /etc/init.d/samba reload

Securing Samba

This section was started to give some general advise on security considerations and is not an exhaustive review of samba security.


Networking Section - use "hosts allow" and "hosts deny"

# hosts allow =

hostal allow =

hosts deny =

hosts deny = all others.


When defining a share, consider the following options :

browseable = no ~ Shares will not show up when browsing your network.

users = user1 user2 ~ List of users able to access the share

When setting up a Samba share, you can limit the users who have access to your share


comment = Private Share

path = /path/to/share/point

browseable = no

read only = no

valid users = user1 user2 user3

Now only samba users user1, user2, and user3 will have access to the share "private".


Configure your firewall (iptables) to limit access to your server. Samba uses ports

UDP ports 137 and 138

TCP ports 139 and 445

Troubleshooting Samba

A common problem when attempting to access a SMB share from a Windows computer is "System Error 53" after attempting to "Net Use".

The first thing you should do, before looking into your conf files, is ensure that the directory you are sharing actually exists.

If you are having problems with Samba users, look into the command pdbedit

Tips / Permissions

Samba permissions are sometimes a little tricky.

Server side

The name of your samba share is the word on the [ ] [private] = share name of "private". [secret] = share name of "secret".

To be able to mount the samba share, samba users on the server must have permission to access the directory.

If /path/to/share/point in "path = /path/to/share/point" is owned by root.root with permissions of 770 , only root will be able to mount the share.

Client side

If you do not user a credentials file, do not forget to specify your samba_user at the time of mounting ( -o username=samba_user ).

Permissions on a samba share depend on the Server.

Linux servers will honor full Linux permissions.

Windows shares do not support Linux permissions. Set permissions at the time of mounting the samba share with the options file_mode=660 and dir_mode=770 (these are permissions and not umask values):


If the server does not support the CIFS Unix extensions this over‐

rides the default file mode.


If the server does not support the CIFS Unix extensions this over‐

rides the default mode for directories.

These options will be used for all files and directories on the (Windows) samba share and can not be changed.

Permissions of new files on the samba share are set by your umask.

To mount your samba shares via (server) hostname rather than IP Address, add an entry for your server in /etc/hosts (C:\WINDOWS\system32\drivers\etc\hosts for Windows).