Table of Contents

Ubuntu - Samba - Samba Configuration

This example configuration will server out data from two directories.

The “archive” directory will be read only for items we want everyone to see, but never change.

The “incoming” directory will be read/write for all users. Sort of a /tmp on a windows share allowing users to make data available to others. The incoming directory will also be a place the windows machines can put data that an admin can move to the archive section manually. This is a perfect solution for a home LAN or small corporate network.

/etc/samba/smb.conf
#============= Global Settings =======================#
 
[global]
   bind interfaces only = yes
   deadtime = 15
   default case = lower
   disable netbios = yes
   dns proxy = no
   domain master = yes
   encrypt passwords = true
   guest ok = yes
   guest only = yes
   hosts allow = 10.10.10.0/255.255.255.0 127.0.0.1
   hosts deny = all
   interfaces = em1
   invalid users = nobody root
   load printers = no
   max connections = 10
   netbios name = samba
   preferred master = yes
   preserve case = no
   printable = no
   security = share
   server string = Samba Share
   socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=65536 SO_SNDBUF=65536
   strict sync = no
   sync always = no
   syslog = 1
   syslog only = yes
   workgroup = WORKGROUP
 
#============ Share Definitions =======================#
 
[incoming]
        create mask = 0400
        directory mask = 0700
        path = /big_disk/incoming
        writeable = yes
 
[archive]
        path = /big_disk/archive
        writeable = no

Configuration options: step by step


Share Definitions


Starting the install

Step 1: Install samba from package or from source. For the example we are using the package from OpenBSD which is Samba v3.01.

Step 2: Place the smb.conf file from above into the /etc/samba/ directory named smb.conf. You should backup the default smb.conf file the package places there for future reference if you want to.

Step 3: Setup the directories we are going to share files from. The two directories “archive” and “incoming” are under /big_disk in the example. The windows machines are going to access samba shares as the “nobody” user. Thusly, all files and directories we want the windows share to access must be accessible by the user “nobody”. For admin purposes we also are going to use the user “admin_user”. The admin_user can do cleanup and move files from “incoming” to “archive” for read only access if needed.

This is what our example structure would look like.

admin_user@machine: ls -la /big_disk/
drwxr-xr-x  11 root        wheel   512 Jan 10 10:20 .
drwxr-xr-x  16 root        wheel   512 Jan 10 10:20 ..
drwxr-x---   8 admin_user  nobody  512 Jan 10 10:20 archive
drwxrwx---   2 admin_user  nobody  512 Jan 10 10:20 incoming

Executing the deamon

To start samba now that it is installed and the smb.conf from above is in place we can use the following lines. Two daemons actually make up the samba service, smbd and nmbd. You can execute the following lines by hand to start samba now.

/usr/local/libexec/smbd /etc/samba/smb.conf
/usr/local/libexec/nmbd /etc/samba/smb.conF

To start samba at boot, place the following in your /etc/rc.local

/etc/rc.local
# samba ( /etc/rc.local )
if [ -x /usr/local/libexec/smbd ]; then
   echo -n ' samba'
   /usr/local/libexec/smbd /etc/samba/smb.conf
   /usr/local/libexec/nmbd /etc/samba/smb.conf
fi

Re-read the smb.conf after making any changes

After you make any modifications to the smb.conf file you will need to notify the smbd and nmbd daemons of the changes. To do this, you can restart Samba by manually killing smbd/nmbd and starting them again or send a HUP to smbd/nmbd. The HUP will tell both daemons to reread the config file without actually having to restart. Either option will work.

## Option: manually kill and start on OpenBSD
pkill smbd;pkill nmbd
/usr/local/libexec/smbd /etc/samba/smb.conf
/usr/local/libexec/nmbd /etc/samba/smb.conf
 
## Option: HUP on OpenBSD
kill -HUP `cat /var/run/smbd.pid`
kill -HUP `cat /var/run/nmbd.pid`

Mounting a smbfs/cifs network export

To mount the samba partition to a Linux or BSD box on the network you can use the following line.

Place it in the /etc/fstab on the machine you want to mount from.

In this example we have two machines, samba_box which runs samba and another machine called BSD_box where we want to see the files from. This line will mount the directory /big_disk/archive from //samba_box to /dir_name on BSD_box. The mount will be read only and log in as guest. This works fine with the example smb.conf from above.

/etc/fstab
## Samba mount (from BSD_box to samba_box)
//samba_box/big_disk/archive   /dir_name   cifs   ro,username=guest,password=guest 0 0