Thursday, August 11, 2011


So I setup a Samba server running on an Ubuntu headless machine. From the terminal go ahead and install the server portion. You could also install smbclient if you need to.
sudo apt-get install samba
Edit the /etc/samba/smb.conf file in your favorite text editor. Make sure the following two lines are not commented out and have the right values for your network.
 workgroup = MyNetwork
 security = user
Now your linux machine will be visible on the windows workgroup you specified and logging on will be secured by a unix account.

You will need to create linux user accounts on the machine for any user you want to use a samba share under this configuration. Also, you will need to add the users to the samba password database. I assume you can figure out how to create user account and add them to the appropriate groups, but this is how you add and enable those users to the samba password file...
sudo smbpasswd -a username
sudo smbpasswd -e username
This allows you to have a lot of user accounts on the computer but control access using samba instead of the OS only.

Now Create a new share at the bottom of the file, or uncomment any of the examples. Here is an example folder share from the Ubuntu server manual...
    comment = Ubuntu File Server Share
    path = /srv/samba/share
    browsable = yes
    guest ok = yes
    read only = no
    create mask = 0755
comment: a short description of the share. Adjust to fit your needs.

path: the path to the directory to share.

This example uses /srv/samba/sharename because, according to the Filesystem Hierarchy Standard (FHS), /srv is where site-specific data should be served. Technically Samba shares can be placed anywhere on the filesystem as long as the permissions are correct, but adhering to standards is recommended.

browsable: enables Windows clients to browse the shared directory using Windows Explorer.

guest ok: allows clients to connect to the share without supplying a password.

read only: determines if the share is read only or if write privileges are granted. Write privileges are allowed only when the value is no, as is seen in this example. If the value is yes, then access to the share is read only.

create mask: determines the permissions new files will have when created.

Make sure to create the directory that corresponds to this share and set the proper ownership and permissions...
sudo mkdir -p /srv/samba/share
sudo chown /srv/samba/share/
I wanted a couple of different types of shares, so I create the following shares  for my little file server...
  comment = "Shared by all users on this system that are part of the sambashare group"
  path = /path/to/share
  browsable = yes
  guest ok = no
  read only = no
  create mask = 0770
  directory mask = 0770
  force group = @sambashare
  valid users = @sambashare

  comment = "Only accessable by the user named Rick"
  path = /path/to/Rick
  browsable = yes
  guest ok = no
  read only = no
  create mask = 0770
  directory mask = 0770
  force user = rick
  force group = rick
  valid users = rick
This is a nice way to have a shared directory that all valid users on the system can access and a private share for each user on the system. I have no idea if this is a standard way of accomplishing this, but it works really well for us.

The "create mask" and "directory mask" options are used to define the default permissions applied to any new files or directories that the user creates. Likewise, the "force user" and "force group" options determine the ownership of the files and directories. Notice for the first share I left out the "force user" option and set the "force group" option to @sambashare. This is nice because the ownership of any new files or directories are owned by the user that created them.

You can restart the two samba services like so to get started...
sudo restart smbd
sudo restart nmbd
Also, the following command is useful to parse the configuration file and see if there were any problems are suggestions...
testparm /etc/samba/smb.conf

Monday, August 1, 2011

Raid 1

Wow!! I was doing some research into setting up a linux file and print server and came across the concept of software Raid in linux. Are you kidding me!! Raid 0, 1, 5, etc. can all be done at the linux kernal level without the need of any special Raid hardware. The linux community is amazing! I love it.

So, I have an older desktop I wanted to use as a file and print server for the household and decided to set it up with a simple 2 disk Raid 1. This means the 2 hard drives are mirrored. You can have one hard drive completely fail and lose no data at all. This is perfect for a little light duty file server.  This is a bit slower than a one drive system, but that is not important because I am mostly concerned that I don't lose any data from the past 20 years.

I started by connecting 2 identical 300 gigabyte IDE hard drives that I already had in a ~8 year old computer. An old computer should work fine for this sort of need to spend any money at all.

You can follow the Ubuntu website documentation for setting up the Raid at installation time like I did at...

I setup identical boot and swap partitions on these two identical hard drives, and then created two Raid devices to mirror the respective partitions (md0 & md1). It is quite amazing that you can do all of this at installation time and the drives just start to sink up seamlessly in the background.

Drive 1:
sda1 - /boot
sda5 - /swap

Drive 2:
sdb1 - /boot
sdb5 - /swap

Once you have the Software raid setup, you can use the mdadm software to manage it.

cat /proc/mdstat

sudo mdadm --query --detail /dev/md0