Printed from http://kimbriggs.com

Basic Samba Setup for a Home Fileserver with Nightly Backups using rsync

Updated 2012-01, Ubuntu 10.04.03 LTS.

Summary of Samba Fileserver Network Objectives

You are tired of having several copies of the same file on different computers, or figuring out which computer you have a certain file on. You have a trusted LAN, either at your home or a SOHO (Small Office Home Office) type of setup and you would like to have one central place for every person (every computer) to work off of.

It is truly a trusted LAN and you are not concerned about security. In other words, you don't want to have to enter a username and password. You want all files to be owned by the same user on the central fileserver and be equally accessed by anybody on the network. You want it to appear that the user is working on files on the local machine.

If you have a situation similar to the above, I recommend you do like the big enterprise corporations and use linux where it is well suited and completely ready for use, as a central fileserver. This setup has saved me lots of time, some money, and prevented a lot of aggravation.

Requirements:A dedicated computer that you can leave on all the time, or at least will be on when any other computer in the network is being used. An extra hard drive. A linux distribution containing the Samba package. I have described a setup using Ubuntu linux (it's free). This most likely means the method would work for Debian GNU/linux as well. A safe minimum is Pentium III and 256MB RAM. A nice fileserver would be a P4 with 500MB RAM.

Samba Background

Samba is a an open-source software package that runs on non-MS Windows machines that lets you communicate with Windows servers and clients. It can work on linux-linux machines as well, but I'm of the opinion that the NFS (Network File System) is better suited for that task. There is a lot of documentation on the Samba website and included in the Samba package. Go to those places if you really want to learn the details.

***Do not use this method if you are concerned about protecting sensitive data***.

The Samba package for linux/UNIX is capable of enterprise-wide file sharing and handling different types of security authentication. The default setup is, in fact, very secure and it took me a while to figure out the settings for a "wide open" sharing setup. I have included a summary of the settings you need to make Samba INSECURE.

Description for "How-To" Samba Fileserver based on Ubuntu Linux

Using the Synaptic front-end to the apt-get package management tool, it is very easy to get Samba Server up and running. Then by joining the Windows workgroup for you LAN, you're almost done. The real trick comes in modifying the Samba configuration file, /etc/samba/smb.conf. First the easy stuff:

Initial setup of Linux Samba file-server and Windows Samba cha-cha-cha client.

If you are sure the computers can talk to each other (ping), and you have installed the Samba server as described above, the only other thing you need to do is replace the file /etc/samba/smb.conf with the one below. Make sure you make a backup of this file by calling it smb.conf_ORIG or something and only work on the new one. For example, if you had the file in the grey box below in your home directory and it was named "smb.conf", then you could use these 3 commands.

me@myhost$ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf_ORIG
me@myhost$ sudo mv smb.conf /etc/samba/smb.conf
me@myhost$ sudo smbd restart
me@myhost$ sudo nmbd restart

Looks pretty simple, right? There is a huge amount of information for all of the modifications and security measures you can make to samba in the original smb.conf file. I tried working with it for a while and gave up. In some debian tutorial on samba, they gave a tiny sample file to test with and I worked from that. The file comment said, "Please for testing only", so this is your last reminder that this will make your files totally INSECURE.

# /etc/samba/smb.conf file for COMPLETELY INSECURE SHARING
# You need to replace each "USER_NAME" instance with your username
# Apps... Accessories... gedit Text Editor. Search... Replace

[global]
workgroup = WORKGROUP
server string = SambaServer
security = share
name resolve order = hosts lmhosts

[Documents]
path = /home/USER_NAME/Documents
force user = USER_NAME
force group = USER_NAME
read only = no
guest ok = yes

[Downloads]
path = /home/USER_NAME/Downloads
force user = USER_NAME
force group = USER_NAME
read only = no
guest ok = yes

[Music]
path = /home/USER_NAME/Music
force user = USER_NAME
force group = USER_NAME
read only = no
guest ok = yes

[Pictures]
path = /home/USER_NAME/Pictures
force user = USER_NAME
force group = USER_NAME
read only = no
guest ok = yes

[Public]
path = /home/USER_NAME/Public
force user = USER_NAME
force group = USER_NAME
read only = no
guest ok = yes

[Templates]
path = /home/USER_NAME/Templates
force user = USER_NAME
force group = USER_NAME
read only = no
guest ok = yes

[Videos]
path = /home/USER_NAME/Videos
force user = USER_NAME
force group = USER_NAME
read only = no
guest ok = yes

# This is not a Ubuntu default.
# You need to create a directory "Voice" to use.
# I use for lectures, foreign languages, etc.
# Delete the "#" symbols BELOW this line to activate sharing.
# [Voice]
# path = /home/USER_NAME/Voice
# force user = USER_NAME
# force group = USER_NAME
# read only = no
# guest ok = yes

# You don't need the lines below unless you develop websites
# [Websites]
# path = /home/USER_NAME/public_html
# force user = USER_NAME
# force group = USER_NAME
# read only = no
# guest ok = yes

To make things simple: On your Windows clients, you should automatically be able to see the shares through "My Network" (Network Neighborhood). To make the files easier to access, I suggest you create shortcuts within your "My Documents" folder. I was able to delete and recreate "My Music" and "My Pictures" as shortcuts to the fileserver's directories, but the name has to be exactly the same, or else Windows will keep re-creating them for you. The only drawback to this is that you will have a folder "My Documents\Documents", which could mean an extra click at times. On the other hand, it helps to "cleanup" the My Documents folder into a few, high-level directories.

Example: Open up My Documents --> Empty My Pictures (because you've already got them on your fileserver, right?) and delete it --> Click File...New Shortcut --> Use the wizard to browse to the folder on the network that you want (e.g., Pictures). If it doesn't give you an opportunity to rename it, right-click the new shortcut and rename it "My Pictures".

The lmhosts or hosts file: All I have right now is a Windows XP machine where they are kept in C:\windows\system32\drivers\etc. I can't remember if you need this for samba or not, but you'll definitely need it if you use virtual directories on your development machine.

To arrange nightly backups:

  1. Add the extra hard drive to the linux file server.
  2. Choose a nice and easy "mount point" (location) for it like "/backup".
  3. Make it owned by your user:

    me@myhost$  sudo chown -R "USER_NAME" /backup
    me@myhost$  sudo chgrp -R "USER_NAME" /backup

  4. Create a text file (shell script) to execute the rsync program for each directory (see below).
  5. Schedule a cron job to run nightly and execute the shell script.

Contents of shell script "backup.sh". This is an example of a computer with 2 active users. Each user's entire home director is backed up. You need the trailing slash for the first location.

rsync -av /home/USER_NAME1/   /backup/USER_NAME1
rsync -av /home/USER_NAME2/   /backup/USER_NAME2

Check the backup directory once in a while to clean up deleted files you are SURE you don't need. The -av options do NOT delete files. They update existing files to newer versions and add files not yet in the backup folder.

If you got this far, you might be interested in the various linux programs that are available for use on your server.

It is hard to describe how much easier computer networking / maintenance has been since I installed this setup. I don't have any special interest in rsync or Ubuntu linux, but they have proven to be a big help.

Buy gold online - quickly, safely and at low prices

 
CC License Ubuntu Get OpenOffice Graphics by GIMP Bluefish Editor Eliminate DRM Get Firefox php.net Play Ogg what's this?