Thursday, August 11, 2011

Samba

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...
[share]
    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 user.group /srv/samba/share/
I wanted a couple of different types of shares, so I create the following shares  for my little file server...
[Share]
  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

[Rick]
  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
Links:

https://help.ubuntu.com/11.10/serverguide/C/samba-fileserver.html
https://help.ubuntu.com/community/Samba/SambaServerGuide
http://www.handson.ca/tutorials/samba.html
http://www.linuxquestions.org/questions/linux-networking-3/samba-cups-access-denied-unable-to-connect-error-322874/

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 thing...no 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...

https://help.ubuntu.com/community/Installation/SoftwareRAID

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



Links:
http://www.howtoforge.com/replacing_hard_disks_in_a_raid1_array
https://help.ubuntu.com/community/Installation/SoftwareRAID
http://en.wikipedia.org/wiki/RAID
https://help.ubuntu.com/10.04/serverguide/C/advanced-installation.html
http://www.howtoforge.com/replacing_hard_disks_in_a_raid1_array
http://nwlinux.com/diagnosing-a-degraded-ubuntu-raid-1-array/
http://advosys.ca/viewpoints/2007/04/setting-up-software-raid-in-ubuntu-server/
http://tldp.org/HOWTO/Software-RAID-HOWTO-2.html
http://ubuntuforums.org/showthread.php?t=408461
http://www.linuxjournal.com/article/6412
http://www.linuxjournal.com/article/5898
http://shop.oreilly.com/product/9781565927308.do
http://www.howtoforge.com/replacing_hard_disks_in_a_raid1_array
http://www.brighthub.com/computing/linux/articles/37236.aspx#
http://tldp.org/HOWTO/Partition/setting_up_swap.html
http://en.wikipedia.org/wiki/Mdadm#Types_of_physical_device
http://www.ducea.com/2009/03/08/mdadm-cheat-sheet/
https://help.ubuntu.com/community/Installation/SoftwareRAID
http://www.handson.ca/tutorials/samba.html