Installing SAMBA 3.0
SAMBA lets you map drives with Windows systems (FreeBSD 5.2)
Posted 04.11.2004 | Updated 23.05.2006 | Contributed by Andy Mallett


SAMBA allows a Unix box to share directories and access other network shares in a similar way to MS Windows, using the Server Message Block protocol (SMB - hence SAMBA).

Today's recipe will be using samba-3.0.12.tar.gz [15MB] or grab another version from those rather fine people at samba.org.

We will also be downloading it to our /src directory, for short path typing which is much easier on the fingers.

If you use /usr/local/src, change these directions accordingly..

1. Installation

Installation is the same as ever..

cd /src

tar -zxvf samba-3.0.12.tar.gz

cd samba-3.0.12/source

./configure

make

make install


Be flexible with file locations
Note that different versions of Samba tend to install files in slightly different places. It doesn't really matter, as long as you know the important filenames (as shown in these instructions) and how to find them. Especially watch what goes in those /bin, /samba, /sbin, lib and /etc directories and note that /usr/local/samba has both /bin and /sbin subdirectories, so adjust your settings accordingly.

2. Configuration

Create the log file and directory:

mkdir /var/log/samba
touch /var/log/samba/samba.log
chmod 755 /var/log/samba/samba.log

Secure all Samba files using the chmod command.
- smbd and nmbd should be readable by all and writable ONLY by root; smbd sould also be executable by all:

cd /usr/local/samba/sbin
chmod 755 smbd
chmod 755 nmbd


- the samba.log file should be readable and writable ONLY by root, it may contain secrets.

Next create a configuration file, from scratch, like a real man:

vi /usr/local/samba/lib/smb.conf

Here is my own, rather minimalist smb.conf file.

Samba will run according to what's in this file These settings are the equivalent to Windows Share Level Permissions. Additionally the permissions on the shared directories themselves will also influence what a user can do once they've mapped to these shares. These directory permissions, set using chmod, are the equivalent to Windows NTFS permissions...

drwxrwx--- 2 root wheel 512 Nov 9 11:14 andys
drwxrwxr-x 2 root wheel 512 Nov 9 11:53 files
drwxrwxr-x 2 root wheel 512 Nov 9 11:14 images


Note above that others are not even allowed to read the andys directory (bugger y'all)..

3. Authorise Users

Make a user on the Freebsd system:

adduser

See Adding users

Next make this user a Samba user by adding the username to the smbpasswd database file. This must be the same username/password combo as the original username:

/usr/local/samba/bin/smbpasswd -a username

This user account will be able to map to the shared directories, with the specified Samba and Directory permissions.

Testing the configuration

Start the smbclient..

/usr/local/samba/sbin/smbd start - starts the samba daemon..
/usr/local/samba/sbin/nmbd start - starts the samba password daemon

Note samba needs to be restarted every time you modify smb.conf..

smbd restart

Run testparm to get a readout of the samba configuration..

/usr/local/samba/bin/testparm

To save this file type:

testparm > testparm.copy

Then you can more the testparm.copy file and read it at your leisure. The testparm command will tell you all about your Samba configuration. The first line indicates where to find the smb.conf file. Press enter when prompted to see a dump of the services you set up in the config file. If you get errors, fix the line the error points to.

Run a test mount..

I find this can be useful in troubleshooting the configuration setup. The samba services are specified as a UNC path: \\computername\sharename (aka service name). However, under Unix the \\ characters must be 'escaped' with two extra \\, as below. Make sure the format is correct:

smbclient \\\\server\\\share

For example:

smbclient \\\\hyperbox\\\andys

And finally map a drive from another machine to the Unix shares..

Make SAMBA start automatically

It can be a bit of a drag manually starting smbd and nmbd every time the box boots up. You're a busy person with an uptight schedule, so why not enable the samba daemons (smbd and nmbd) to run from inetd.

Edit and enable inetd.conf - remove the # symbols in front of the two samba lines and modify the path as required..

vi /etc/inetd.conf
netbios-ssn   stream   tcp   nowait   root   /usr/local/samba/sbin/smbd   smbd
netbios-ns   dgram   udp   wait   root   /usr/local/samba/sbin/nmbd   nmbd


Finally get a start-up script from '/src/samba-3.0.12/packaging/LSB/samba.sh' directory and copy this to '/usr/local/etc/rc.d' - smbd and nmbd will be started when you boot your computer..

cp /src/samba-3.0.12/packaging/LSB/samba.sh  /usr/local/etc/rc.d

Reboot for it all to happen. Now you can map drives, just like it's a Windows box. Except this one will be reliable, of course.


Related Links

The Official Samba-3 HOWTO and Reference Guide
Samba-3 Configuring smb.conf
Sharing with Samba under Linux
Setting Up A Samba Server with Windows XP Clients