Thursday, April 2, 2015

Installing and Configuring Samba4 on Raspberry Pi Model B for file sharing

The task:


Today we will be installing and configuring Samba4 server on a Raspberry Pi Model B running Arch Linux Arm. Just in case you haven't installed Arch Linux Arm on your Pi, you can refer to my post on Installing Arch Linux Arm on a Raspberry Pi Model B. Besides learning how to install and configure Samba4 on the Pi, we will be creating a samba share!
       A samba share is basically a network file sharing service, that allows Windows, Mac and Linux clients to access files on the samba server. You can plug in a USB drive or a hard disk to the Pi and share it over the network with any computer! So you can think of it as a cloud storage service on your network that happens to be hosted by you! I can show you how to access your share over the Internet, but I will save that for some other time. So lets get started with our task.

Caution:


Instructions contained in this article were written as a reminder to myself for a fresh install of Arch Linux Arm (Nov, 1, 2014). Since you will be doing things as root, you could brick your Pi if you do something wrong. So, please read through all the instructions carefully before attempting anything. Lastly please backup all the data of your Pi before you do anything.

If you have any questions about this article or find typos in it, please feel free to note it in your comment.
Thanks.

Things required:


  • Raspberry Pi B 512mb (or better) with Arch Linux Arm installed on it and is connected to the Internet. 
  • A USB drive (this will be your share) or a hard drive will also work if you have the SATA or ATA to usb converter for it.
  • Lastly you will need a mouse, keyboard, display and a USB hub to power the Hard disk if your are using one. (Mouse, keyboard, display is not required if you have a laptop or PC connected to the same network as the Pi. Use ssh instead!)

Downloading and installing Samba4:


If your Pi is connected to the same network as your computer, you can just ssh into it from your computer and wouldn't need a mouse, keyboard, and a display! Just use the ssh command in terminal or putty to create a remote connection into your Pi:

ssh root@"your-Pi's-ip-address"
Example: ssh root@192.168.1.5

You can find your Pi's ip address by using the arp command:

arp -a

This will list the IP and MAC addresses of all the devices connected to the network. Look for a MAC address that starts with the following prefix:  "b8:27:eb" in the second column. The ip address corresponding to this MAC address is the ip address of your Pi!

Once you have found your way into the Pi's bash prompt, you can now begin downloading and installing Samba4. To do this use the pacman command at the bash prompt:

pacman -Sy samba

Package Manager or pacman will find Samba4 and all its dependencies and prompt you for your permission to download and install the package. Go ahead and enter Y at the prompt and Samba4 will be installed on your Pi. This process might take a few minutes depending on your Internet connection.

Once Samba4 is installed, we have to enable the smbd and nmbd services. To do this, use the systemctl command:

systemctl enable smbd nmbd

Now that Samba4 is installed on the your Pi, it is a good time to create a group and add users to it so you can share a samba share with them. Use the groupadd command to create a group:

groupadd groupname
Example: groupadd samba

To add users to this group, use the useradd command:

useradd -m -g groupname user
Example: useradd -m -g samba tony

To add this user to the samba database and create a password for this user to access the samba share, use the pdbedit command:

pdbedit -a -u tony

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  Notes  =-=-=-=-=-=-=-=-=-=-=-=-=
"pdbedit" might give the following error:
Can't load /etc/samba/smb.conf - run testparm to debug it

To fix this error navigate to /etc/samba/
Find the file smb.conf.default

Make a copy of smb.conf.default renaming it to smb.conf
cp smb.conf.default smb.conf

then type "pdbedit -a -u tony" again

It will ask you to create a password for the user tony
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

After you have successfully set the new password, you will get a summary of the user details. Remember, the password entered in the "pdbedit -a -u" for a user is only used by samba and won't affect the system login password of the user. If you want to sync the system login password of the user to samba, please refer to pdbedit. Now that we have created the group and added users to it, you have two more things to do i.e. to setup the shares and configure Samba4 to allow users to access these shares. So the next section will show you how to create shares using external storage.

Creating the shares:


There are two ways to create shares. You can either use your Pi's SD card to create one or you could use an external storage device to do this. I would recommend that you use an external storage device because you could just plug in a 1tb hard drive to the Pi and don't have to worry about having your SD card filled up. You can use the Pi's SD card, but that defies the purpose of setting up a Samba4 server in the first place. If we use the SD card for a share, it will eat up system storage as users add their stuff to the share. So in this article I will be showing you how to create a share using an external hard drive, which was formatted for an Apple device.
       Apple uses the NSF/NSF+ partitioning scheme, and Linux dose not support it out of the box so we will have to install some helpers before we are able to mount it to the system. The process for mounting a DOS partition does not require the helpers as Linux natively supports DOS FAT35 partitioning scheme. You could skip the next section if you plan to use a USB drive not formatted in NSF/NSF+ format.

Mounting a NSF/NSF+ formatted drive:


First we will install our helper program "hfsprogs." To install the program we will use the pacman command:

pacman -Sy hfsprogs

Pacman will find the program and list all its dependencies. Enter Y and press enter to start the installation. Enter Y and press enter to start the installation. Once the installation is complete, we have to connect the hard disk using a SATA to USB bridge/cable. If you are using an SSH connection instead of controlling the Pi directly, you will not be able to see if the hard disk was successfully detected by the Pi. When a hardware device is connected or removed from the Pi, it displays a status message on the connected screen. Since we don't have that, we can use fdisk command to list all connected disks:

fdisk -l

You should get a similar output:

Disk /dev/sda: 298.1 GiB, 320072933376 bytes, 625142448 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: DA6265FD-C5DA-4D3F-B835-E6520CF19293

Device         Start       End   Sectors   Size Type
/dev/sda1         40    409639    409600   200M EFI System
/dev/sda2     409640 623872871 623463232 297.3G Apple HFS/HFS+
/dev/sda3  623872872 625142407   1269536 619.9M Apple Boot

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  Notes  =-=-=-=-=-=-=-=-=-=-=-=-=
sda  = disk name [sdb would be another hard disk]
sda1 = 1st partition [sdb1 = 1st partition of the sdb disk...]
sda2 = 2nd partition
sda3 = 3rd partition
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Before we mount the partitions we need to create a mount point for the partition. This is very simple. To create a mount point, we will create a directory. We will use this directory to mount our partition. Best practice is to create a mount point in "/mnt". So, navigate to /mnt and create a directory in it. Make sure you restrict the use of symbols in the directory name and try to keep the length of the directory name less than 9 characters. Sometimes windows clients won't connect to the share if the mount point name is too long or if it contains special symbols. Once the mount point is created, use the mount command to mount your partition to the mount point:

mount -t hfsplus /dev/sda2 /mnt/mac

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  Notes  =-=-=-=-=-=-=-=-=-=-=-=-=
Command   option   FileSystemType    Partition    Mount point
mount     -t       hfsplus           /dev/sda2    /mnt/mac

In this example the 2nd partition of sda disk is being mounted
on the mount point /mnt/mac
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

After pressing enter, if the prompt returns without any output, than the mount was successful and no further action is required. If there is an output, it will give you a reason of the error and some pointers on how to fix the error. Now that we are done with mounting a NSF/NSF+ formatted drive, it is time to configure Samba4 for file sharing.

Configuring Samba4 for file sharing:


To configure Samba4, we will have edit the samba configuration file "smb.conf" with is located at /etc/samba/ The only thing we need to edit in the configuration file is the very last section. By default the last section looks like this:

# The following two entries demonstrate how to share a directory so that two
# users can place files there that will be owned by the specific users. In this
# setup, the directory should be writable by both users and should have the
# sticky bit set on it to prevent abuse. Obviously this could be extended to
# as many users as required.
;[myshare]
;   comment = Mary's and Fred's stuff
;   path = /usr/somewhere/shared
;   valid users = mary fred
;   public = no
;   writable = yes
;   printable = no
;   create mask = 0765

In this section every thing is commented out. We can use this as a template for out configuration file. After populating the proper values I get this:

[SambaShareTony]
 comment = Tony's share
 path = /mnt/mac
 valid users = tony
 public = no
 writable = yes
 printable = no

Put your edited version under the commented out section and save the smb.conf file. Once it is saved, restart the samba server by entering the following command:

systemctl restart smbd.service

Now you should be able to connect to the samba share from any computer on the same network that supports samba. That's about it!


Thursday, January 1, 2015

Mounting a WebDAV Share on Mac OS X

The task:


In this tutorial we will learn how to mount a WebDAV share as a remote network drive on Mac OS X. The setup on a Mac is quick and easy as compared to a Windows machine. To learn how to do this on windows, read my blog on Mounting a WebDAV share on Windows 7.

Caution:


In order to create a secure connection to your WebDAV share, make sure you use https:// instead of http:// in your WebDAV address!

If you have any questions about this article or find typos in it, please feel free to note it in your comment.
Thanks.


Things required:

  • Mac OS X
  • Internet Connection
  • "WebDav" address

Mounting the WebDAV share in Finder: see video

  1. Click anywhere on your desktop. Now in the top menu bar click on Go. Click Connect to Server from the drop down menu.
  2. Connect to Server" window will appear. In the Server Address field add your WebDAV server address (Example: https://server.bbc.com/path/to/shared/folder) or (https://108.211.78.190/Shared-Documents). Click Connect.
  3. Click the radio button next to Registered User. Enter your credentials (Name = Username). Click Connect.

You are done! The WebDAV share is now mounted. You can easily find it under Shared tab in the Finder window.

Wednesday, December 31, 2014

Mounting a WebDAV Share on Windows 7

The task:


In this tutorial we will learn how to mount a WebDAV share as a remote network drive on Windows 7. The setup on Windows 7 is not very straight forward, as it requires editing the registry. Those of you who have not edited a registry before, just follow the directions very carefully. It is important to note here that editing the registry incorrectly, may mess up your computer. So, follow the steps very carefully! If you are using a Mac, please refer to Mounting a WebDav Share on Mac OS X.

Caution:


Before we get going, we need to fix some bugs that Windows 7 so conveniently comes with! By default, Microsoft has kept the authentication level for WebClient to none. We need to fix this in the registry in order to avoid giving away our password to the online world. Secondly, we have to fix the File Attributes Limit bug, which prevents windows from enumerating more than 1000 files in a folder. Lastly, we will have to install an update from Microsoft that enables WebClientServices, which makes it possible for Windows 7 to connect to a WebDAV share.

If you have any questions about this article or find typos in it, please feel free to note it in your comment.
Thanks.


Things required:

  • Windows 7 64-Bit.
  • Internet Connection.
  • "WebDAV" address.
  • Patience.

Fixing the Authentication bug in the registry: see video

  1. Click on Start from the Taskbar. Type regedit and press Enter.
  2. Click on Yes in the "User Account Control" pop up window.
  3. Locate and click the following registry subkey:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WebClient\Parameters
  4. Once you are in "Parameters", find BasicAuthLevel.
  5. If BasicAuthLevel is listed in the right half of the "Register Editor" window, skip to step 6. Else, in the Edit menu, point to New, and then click DWORD Value. Type BasicAuthLevel for the name of the DWORD, and then press Enter.
  6. Right-click BasicAuthLevel, and then click Modify.
  7. Set the Value data box value to 2 and click Ok.

    Note: By default the value is set to 0.

Now let's fix the File Attributes Limit bug in the registry: see video

  1. Assuming you have not exited out of the "Register Editor", in Parameters, find FileAttributesLimitInBytes.
  2. If FileAttributesLimitInBytes is listed in the right half of the "Register Editor" window, skip to step 3. Else, in the Edit menu, point to New, and then click DWORD Value. Type FileAttributesLimitInBytes for the name of the DWORD, and then press Enter.
  3. Right-click FileAttributesLimitInBytes, and then click Modify.
  4. Make sure Decimal is selected for "Base". Set the Value data box value to 4294967295 and click Ok.

    Note: If the default value is 1,000,000 (1 MB), Windows will enumerate a maximum of approximately 1,000 files in one folder. The actual maximum number of files may vary, depending on the number of file attributes or file properties. By default, the WebClient service does not ask for specific WebDAV properties. Therefore, the server returns all file attributes. The Microsoft Office-integrated Webfolders redirector does ask for specific WebDAV properties.

  5. Exit Registry Editor.

Installing the KB907306 update from Microsoft:

  1. Point your internet browser to: " http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=15123 ".
  2. Click on the red Download button. The download will start.
  3. Once the download has completed, locate the file on your computer hard disk. It is named Webfldrs-KB907306-ENU.exe and should be in your default downloads folder.
  4. To start the Setup program, double-click the Webfldrs-KB907306-ENU.exe program file on your hard disk. The default installation location is \Program Files\Common Files\Microsoft Shared\Web Folders.
  5. Follow the instructions on the screen to complete the installation.
  6. Restart your computer.

Mounting the WebDAV share in Windows Explorer: see video

  1. Click on Start from the taskbar. Click on Computer in the start menu.
  2. Click on Map network drive from the menu bar.
  3. Select a drive letter next to Drive:, under Folder: enter the address of your WebDAV folder. (Example: http://server.bbc.com/path/to/shared/folder) or (http://108.211.78.190/Shared-Documents). If you want your computer to automatically mount the WebDAV folder at next logon, check the box next to Reconnect at logon.
  4. Click Finish. An authentication window will appear, enter your credentials and click Ok.

You are done! The WebDAV share is now mounted. You can easily find it under Computer from the Start menu.