Thursday, June 26, 2014

Setup a Samba Media Server on uBuntu

1. Prerequisites
- Your Linux box should have an static ip-address.
In case you're getting your ip from a router/server via DHCP make sure it's configured to provide a fixed dhcp-lease. If that's no valid option you cannot use WINS ... more on this way down.
- You need to have samba installed.
If you haven't done so already open a terminal and type:

Code:

sudo apt-get install samba

Don't close the terminal upon installation - we still need the commandline to get several tasks done!
2. Getting samba configured
First, let us make sure samba isn't running:

Code:

sudo /etc/init.d/samba stop


As a starting point I included an smb.conf below, and there are only a few simple things you may need to tweak.

Since the installation of samba just installed a rather useless template file we're going to rename it - we keep the file just in case.



Code:



sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.template


Next we create a new empty file



Code:



sudo touch /etc/samba/smb.conf


And finally we need to open the file inside an editor



Code:



sudo gedit /etc/samba/smb.conf


NOTE: If you're on KDE replace "gedit" with "kate"


Copy / Paste the contents of the code-section below into your editor and read on ...



Code:



[global]
; General server settings
netbios name = YOUR_HOSTNAME
server string =
workgroup = YOUR_WORKGROUP
announce version = 5.0
socket options = TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192

passdb backend = tdbsam
security = user
null passwords = true
username map = /etc/samba/smbusers
name resolve order = hosts wins bcast

wins support = yes

printing = CUPS
printcap name = CUPS

syslog = 1
syslog only = yes

; NOTE: If you need access to the user home directories uncomment the
; lines below and adjust the settings to your hearts content.
;[homes]
;valid users = %S
;create mode = 0600
;directory mode = 0755
;browseable = no
;read only = no
;veto files = /*.{*}/.*/mail/bin/

; NOTE: Only needed if you run samba as a primary domain controller.
; Not needed as this config doesn't cover that matter.
;[netlogon]
;path = /var/lib/samba/netlogon
;admin users = Administrator
;valid users = %U
;read only = no

; NOTE: Again - only needed if you're running a primary domain controller.
;[Profiles]
;path = /var/lib/samba/profiles
;valid users = %U
;create mode = 0600
;directory mode = 0700
;writeable = yes
;browseable = no

; NOTE: Inside this place you may build a printer driver repository for
; Windows - I'll cover this topic in another HOWTO.
[print$]
path = /var/lib/samba/printers
browseable = yes
guest ok = yes
read only = yes
write list = root
create mask = 0664
directory mask = 0775

[printers]
path = /tmp
printable = yes
guest ok = yes
browseable = no

; Uncomment if you need to share your CD-/DVD-ROM Drive
;[DVD-ROM Drive]
;path = /media/cdrom
;browseable = yes
;read only = yes
;guest ok = yes

[MyFiles]
path = /media/samba/
browseable = yes
read only = no
guest ok = no
create mask = 0644
directory mask = 0755
force user = YOUR_USERNAME
force group = YOUR_USERGROUP


Ok, I already mentioned that there are a few simple things you may need to tweak; so here they are:

-> netbios name = YOUR_HOSTNAME


Replace "YOUR_HOSTNAME" with your desired hostname (don't use spaces!). Best pratice would be to use the same name you configured upon installation.


Example:


netbios name = DAPPER


-> workgroup = YOUR_WORKGROUP


Replace "YOUR_WORKGROUP" with the name of your workgroup, but make sure you're using the same as configured in Windows.


To find out the Workgroup name in Windows follow these steps:


- Click "START"


- Click "Control Panel"


- Click "System"


- Click the 2nd Tab entitled "Computername" and find the name of the Workgroup there.


Example:


workgroup = MSHOME


-> wins support = yes


If your box doesn't have a static ip-address, or you cannot configure your router/server to provide you with a fixed dhcp-lease, change this configuration parameter to "no".


In this case you cannot use the benefits of WINS.


-> [MyFiles]


This is the name of the share. Leave it as it is or adjust it to whatever you prefer. Don't use more than 31 characters and try to avoid spaces!


-> path = /media/samba/


This suggests that you've mounted an hard drive or partition on /media/samba where all the shared files will be stored.


In case you don't have an extra hard drive/partition you may also create folder.


I assume you've been wise enough to put /home onto a separate partition having an reasonable amount of storage space.


To create the folder type (inside a new terminal) ...



Code:



sudo mkdir /home/samba


... and adjust "path =" to read ...

path = /home/samba/


Remember that this is just an example - you are free to put things wherever you like.


-> force user = YOUR_USERNAME


-> force group = YOUR_USERNAME


Well, this should say it all. Replace "YOUR_USERNAME" with the name you use for login (no spaces!).


Example:


force user = stormbringer


force group = stormbringer


Now we completed the part of editing smb.conf


Save the file and close gedit.


Since we are going to share the folder with other users we should now make sure that the permissions are set. Type:



Code:



sudo chmod 0777 /media/samba


NOTE: Don't forget to correct the path to the location you chose above!


That's it - now we need to start samba ...


1.1 Starting samba and setting up user accounts


Let us fire up samba for the first time. Type:



Code:



sudo /etc/init.d/samba start


NOTE: If the above command doesn't work for you, try:



sudo smbd reload


Once Samba has restarted, use this command to check your smb.conf for any syntax errors





testparm


Time to add yourself as an samba user.

NOTE: You will be asked for a password - make sure you use the same as you use for login!



Code:



sudo smbpasswd -L -a your_username
sudo smbpasswd -L -e your_username


In case you need other users to be able to access the share you need to add them to your system AND samba as well. Make sure you use the very same Windows usernames and passwords!

NOTE: Windows XP doesn't set passwords for its useraccount per default. If you haven't set a password on your XP box just press enter when prompted to enter a password for the user account you're about to create!


In the following example we will add an user called "mark" ...


Example:



Code:



sudo useradd -s /bin/true mark
sudo smbpasswd -L -a mark
sudo smbpasswd -L -e mark


The "-s /bin/true" in the first line prevents the users from being able to access the commandline of your linux box ("-s" stands for "shell"). I strongly advise you to follow this recommendation! Don't change that setting to a valid login-shell unless you really know what you are doing!

Repeat this step until you configured all user accounts!



 



File Sharing (Advanced)



We started with the base of Samba file-sharing. The above-mentioned items should be enough to get you started. Next we will add details that you might or might not need.



If you have more than one network card


If you have more than one network card (or interface) then you have to define where you want Samba to run. In smb.conf under the [global] section, add:



interfaces = 127.0.0.1, 192.168.0.31/24
bind interfaces only = yes


The first address (127.0.0.1), is a loopback network connection (it's your own machine). The second address (192.168.0.31), is the address of the card you want Samba to run on, the second number (24) is the subnet default for a CLASS-C network. It may vary depending on your network.



With "bind interfaces only" you limit which interfaces on a machine will serve SMB requests.



You can limit which IP address can connect to your Samba server adding these lines:



hosts allow = 127.0.0.1, 192.168.0.31, 192.168.0.32
hosts deny = 0.0.0.0/0


The loopback address must be present in the first line. The second line deny access from all IP address not in the first line.

Tuesday, June 24, 2014

Enable Chrome Remote Desktop on Linux (Ubuntu)

On linux when running Chrome Remote Desktop extension in chrome you will notice that it does not give you an option to add the computer as shown in the image below

The solution is not that well documented out there on the web, Google?
the following instructions are for Ubuntu, I have tested them successfully on Ubuntu 14.04
Edit:
sudo nano /etc/apt/sources.list.d/chromeos.list
Add the google Repository:
deb http://dl.google.com/linux/chrome-remote-desktop/deb/ stable main
Install:
sudo apt-get update
sudo apt-get install chrome-remote-desktop
sudo /etc/init.d/chrome-remote-desktop start

Then go back to Chrome Remote Desktop Extension and the following option will be available.

Tuesday, June 10, 2014

How to Build Your Own Network-Attached Storage System

With cheap storage readily available, the temptation to build vast libraries of music, movies, photos, and documents is ever present. But when each PC in your home is packed to its aluminum gills with gigabytes upon gigabytes of digital goods, managing all of that data can be a hassle.

Network-attached storage can make wrangling data much easier. Imagine a single machine on your network slinging files to every PC in your home, managing backups, and safeguarding all of your important memories or sensitive data.

Plenty of network-attached storage appliances on the market are ready and able to tackle your storage needs, but buying one can be an expensive option--particularly if you have only a few files that you want to share with a few machines. Things get even more problematic for those users who have terabytes upon terabytes of data: You can expect to pay dearly for a NAS that’s equipped to handle your digital hoard.

Fortunately, building your own NAS is simple. And doing so offers a lot of advantages over forking over your hard-earned cash--build your own, and you can dictate its size, feature set, and storage capacity, and change things on a whim.

Choosing the Software

A wide variety of operating-system options are available for setting up your own NAS. Many popular Linux distributions offer a server-oriented variant, with instructions on getting your file server up and running. But we’re going to keep things simple and go with FreeNAS.

FreeNAS is a popular choice, as it’s fairly easy to configure once all of the hardware is in place. You can download the latest version from the FreeNAS website. Burn the .iso file you download onto a CD or DVD; in Windows 7, just right-click the file and select Burn disc image. For other versions of Windows, you can use the free ImgBurn utility.

Choosing the Hardware

Now that you have a copy of FreeNAS, let’s talk hardware. FreeNAS will run on just about anything, so an old PC you’re not using anymore will work just fine. For optimal performance, you’ll want to have at least 4GB of RAM.

For my FreeNAS build, I pulled a few spare parts together. My NAS centers on a Gigabyte E350N motherboard, equipped with an AMD E-350 processor. I picked this motherboard because it's small, it draws little power, and it can fit into small spaces, yet it offers four SATA ports for my hard drives. When choosing a system (or building your own), make sure that the motherboard has room to support all of the drives you want to use for storage.

I collected three spare 1TB drives for storage, plus a spare DVD drive to handle the installation. When FreeNAS is installed, it takes over the entire drive you install it on. To keep all of the storage drives available, I also grabbed a 2GB USB key, to host the the operating system.

The Setup: Installing FreeNAS

With the hardware selected and the FreeNAS CD at the ready, it’s time to get started.

Insert the DVD and USB key into the computer you’re setting up as your NAS. Before you start the machine up, be sure that the ethernet cable is plugged into the motherboard. You’ll also want to have another computer that’s connected to your network up and running, as you’ll be using it to connect to and configure the NAS.

Start up the PC and enter the BIOS. The steps to getting into the BIOS will vary depending on your motherboard, but the general rule of thumb is to mash the F2, F7, F8, or Delete key while the PC is booting up--watch the monitor after you’ve pressed the power button, and the instructions will scroll past during the normal startup sequence.

Once you’re in the BIOS, set the machine to boot from the optical drive. The steps will once again vary based on your motherboard model, but you should see a section that lists a Boot Priority order. Once you've set that, press F10 to save and exit; the machine will restart, query your optical drive, and then start loading FreeNAS from your CD.

You’ll know that FreeNAS is running when you see a plain blue screen with a list of options. You want to install FreeNAS onto your USB key, so select the very first option. FreeNAS will list arcane drive model numbers, so looking for the capacity of the USB key (in this case, 2GB) should be the easiest approach. Follow the prompts; FreeNAS will warn you that it will delete everything off of the USB key. Click through that message, and then go get a cup of tea while the progress indicator rolls over to 100 percent complete.

Once it’s done, you’ll see a prompt to eject the CD and reboot the machine. When your computer restarts, it should boot FreeNAS from the USB key--if it doesn’t, head back into the BIOS, set the motherboard to boot to the USB key, and restart again.

As FreeNAS is starting up, it will present lots of arcane lines of code, followed by a numbered list and a Web address to connect to. This is normal. That URL is the network address of your new file server. Type that address into a browser on a computer in your home that’s connected to the same network as the NAS, and you’ll reach the FreeNAS configuration screen.

FreeNAS will prompt you for a username and password. The default user name is “admin,” and the default password is “freenas.” You can change the default to whatever you’d like in the FreeNAS options.

If you ever forget your password, resetting it is fairly easy. You need to head over to the NAS, and type the following command:

Python /usr/local/www/freenasUI/manage.py changepassword admin

FreeNAS will then prompt you to enter a new password.

The Setup: Building Volumes

Once you’re logged in, the first thing you’ll want to do is create the file system. Click Storage at the top of the menu bar, and then select Create volume. In the window that pops up, select all the drives you want to include, and give the volume a name.

You’ll have two options to choose from: UFS (Unix File System) and ZFS. We’re going with ZFS, as it offers support for numerous features designed for file servers, such as RAID support, snapshots, and file compression.

Depending on the number of drives in your machine, you’ll see a few new options. With three drives, I get a choice between mirror, stripe, and RAID-Z. Mirror duplicates data from one disc across the others, as RAID 1 would. Stripe splits files among the discs in the array, as RAID 0 would. RAID-Z is essentially a software implementation of RAID 5.

So what does all of that mean? With my three 1TB drives, selecting the mirror type gives me 1TB of total storage capacity, but preserves my data across all drives; if one drive fails, I can replace it and keep moving. Stripe gives me 3TB and a very fast response time; lose one drive, though, and all of that data is gone. RAID-Z is a sort of amalgam of the two: It gives me 2TB of space, and if one of the three drives fails, my data can be rebuilt from the remaining pair while I find a replacement.

Because I like to live on the edge, I’m going with the striped option. It isn’t the safest alternative, but I’ll squeeze out every bit of space, and I can always implement a safer, redundant backup solution later on.

Whatever you choose, be aware that any data on the discs will be wiped. Click Add volume, and moments later your file server is almost ready to go.

Sharing Your Files

You have your storage volume in place, so now you can fill it with photos of pets, as well as your legally acquired media.

FreeNAS makes it easy to share files with Linux, Apple, and Windows computers. You can create as many shared folders as you’d like--say, a Windows/Unix/Apple share for your movies and music collection, and an Apple-specific share for your Time Machine backups.

The first step is to enable the CIFS (Common Internet File System) service. ClickServices on the left, and then click the button for CIFS. Click the wrench next to the CIFS line to set your workgroup, assign other network and user permissions, or just give your NAS a readily identifiable name. You’ll be typing this name in to access your file server from Windows machines.

On the navigation bar at the left, click the tab conveniently labeled Sharing. I’ll set up a Windows share as an example here, but the instructions for Linux and Apple are fairly similar.

Click Add Windows Share, and give it a name in the window that pops up. Click the drop-down menu next to 'Path' to assign your NAS to an address that Windows will be able to find. Select Browsable to Network Clients, as this feature will let you use the Windows Explorer menus to access your NAS as you would any other folder on your PC.

The other options I’ve selected aren’t especially secure. I want this NAS to be readily accessible to everyone, though, and I have a reasonable level of trust in my coworkers.

And we’re done! Just click Start on a Windows machine connected to your network, and in the Run text box (immediately over the Start icon) type \\YourNASnamehere and press Enter. Windows will connect to the NAS, and you can start dropping files in. Feel free to tuck the NAS out of the way. Mine isn’t even connected to a display, as everything we need to do can be handled in a browser on any machine on the network.