Setup Samba on Ubuntu 11.10

Samba is an implementation of the Server Message Block (SMB)/Common Internet File System (CIFS) protocol for Unix systems, providing support for cross-platform file and printer sharing with Microsoft Windows, OS X, and other Unix systems.

This quick guide will setup a samba share on Ubuntu Server 11.10 and configure its access on a Windows 7 client with workgroup networking. To do so, follow these steps:

Update the package list and install samba

$ sudo apt-get update
$ sudo apt-get install samba

You will see the following last two lines on successful installation:

smbd start/running, process 2894
nmbd start/running, process 2921

Next, edit the samba configuration

$ sudo nano /etc/samba/smb.conf

Configure global settings for samba shares

Under [global], enter the following (do not include the curly brackets for netbios name):

netbios name = {my-netbios-name}
workgroup = WORKGROUP

Look for the header ### Authentication ###, and uncomment this line so users are prompted to log on when accessing the share:

security = user

Define the share

Go to the end of the file and create a new share, give it a name you want to refer to when accessing it via your Windows client (note: do not delete the square brackets):

comment = Ubuntu File Server share
path = /srv/samba/share
browsable = yes
guest ok = yes
read only = no
create mask = 0755

Control-X to exit and Yes to save changes to the file.

Ensure changes to the configuration file are correct

$ sudo testparm

You should see the message: Loaded service file OK.

Create the share folder on Ubuntu, and restrict access to the folder

$ sudo mkdir -p /srv/samba/share
$ sudo chown nobody.nogroup /srv/samba/share

Restart services for changes to take effect

$ sudo restart smbd
$ sudo restart nmbd

Create a test file in the ‘share’ folder

$ sudo touch /srv/samba/share/testfile.txt

Test it out on the Windows client

Go to your Windows client (ensure Network Discovery is ON)

  • Under Network, look for the computer {your-netbios-name} (without the curly brackets)
  • Double click to open it. You should see your Ubuntu share that you defined earlier in the smb.conf file, i.e. [your-share-name] (without the square brackets)
  • Click to open it. When prompt to logon, select another user and enter the following:

    Username: <ubuntu-user-name>@<ubuntu-host-name>
    Password: <pwd-for-ubuntu-user-name>

  • You should then see testfile.txt in the share folder.
  • Open it, type some texts and try to save it. You should not be able to. This is as expected.

If you wish to write to the share, do the following in Ubuntu:

  • Create a new group

    $ sudo groupadd -f {group-name}

  • Add the Ubuntu user you wish to grant write access to this new group

    $ sudo adduser {user-name} {group-name}

  • Change the group on the share to this new group

    $ sudo chgrp -R {group-name} /srv/samba/share

  • Grant write access for group privileges on the share

    $ sudo chmod -R g+w /srv/samba/share

Note: replace {user-name} and {group-name} with your chosen Ubuntu username and groupname, without the curly brackets.

Congratulations! You’ve successfully setup samba on Ubuntu Server 11.10.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s