Wednesday, December 21, 2016

Raspberry Pi Home Server

Introduction

https://www.raspberrypi.org/wp-content/uploads/2012/03/raspberry-pi-logo.pngSo , I’m upgrading my home server from MK802 to a Raspberry Pi . The specs are similar , I just wanted to try something new and at the same time give room for implementing IoT in the future.
Anyway , If it’s going to replace my old one, It should act as a
  1. Torrent server
  2. Printing Server
  3. Scanning server
  4. File server.
I'm going to cover these points in this article and update it as time allows. I’ve chosen to start with a headless setup, here I use Jessie Lite , which has no X-Server (no window manager)

Installation

1- Server Image: This step is essential to install operating system on the raspberry-pi. The operating system image can be downloaded from here , and the img file has to be cloned on a micro-SD card (class 10) . I followed the link here , All straightforward.
2- Initial Admin configuration
I connected the pi via putty after connecting it to the network . The default username is pi and password: raspberry
I directly added a new user using adduser command , since this new user is not an admin i used the command adduser myusername sudo to add my new user to the sudoers file.
Now I need to change password for the pi default user , or just delete it completely. I also wanted to change the device name from raspberrypi to something else. So I edited the /etc/hosts and the /etc/hostname files (see the second link below)  using nano then reboot.


Admin Tools

I’d go with webmin anytime i wanted to quickly manage stuff on linux.
sudo nano /etc/apt/sources.list
add the following line
deb http://download.webmin.com/download/repository sarge contrib
close and save , then run this list of commands:
wget http://www.webmin.com/jcameron-key.asc
apt-key add jcameron-key.asc
apt-get update
apt-get install webmin

File Server

Before making the raspberry pi work as a server , I must have a permanent disk space to share. I usually attach a flash drive to the system and make that my transfer space. I use it also as a scratch disk for my torrents clients later on. Doing this , in my opinion , extends the life of the MicroSD on which the system is installed.
so , to display disks I use sudo blkid to get the flash drive UUID value, please look here for guidance.
I go and mkdir /mnt/DownloadDisk for example on a folder in which the flash will mount
Here I use exfat as a filesystem for my flashdrive so the important step here is to install exfat-fuse before doing any fstab changes.
apt-get install exfat-fuse

then I edit the fstab and add the line
UUID=theUUIDyouGot /mnt/DownloadDisk exfat rw,user,uid=65534,gid=65534,permissions,umask=0111,nofail  0 0




Note that uid and gid here are pointing to nouser and nogroup ids respectively. If you don’t know the uid on your system , just use “id nouser” command
Once this step is done, we can work on enabling the file server from webmin. To do this go to webmin , go to the unused modules then to the samba file server node. After enabling it you’ll have.
The final step will be enabling a file share , the samba interface is very clear .. Click on the “create a new file share” and then you’re guided to the next page

The share in my case will point to the /mnt/DownloadDisk , and i will put the ownership to nobody / nogroup with permissions 666 (all read , all write ,nobody executes Open-mouthed smile ) .. also from the share settings , allow the folder to be writable , allow guest and force user to nobody. make sure that the file permission is also set to allow “nobody” user to write.

Torrent Server

sudo apt-get install transmission-cli transmission-common transmission-daemon
Easy .. now I need to setup the daemon and the web user interface so that I have it running on a port I need. To do this , the configuration of the daemon is to be found at /etc/transmission-daemon.
The file which has all the settings you’ll probably need is the settings.json , just copy it , and then edit the original with nano.
IMPORTANT To reflect settings changes on the daemon , it has to be restarted.
To reflect the settings , only use this command
sudo invoke-rc.d transmission-daemon reload
If you don’t do so , the settings will be replaced by the defaults.
The explanation of almost every setting key is present at this site

Print Server

One of the main reasons I went to the idea of configuring a home server was to re-use my USB printers wirelessly and from any other computer at home. It gives you so much power not having to stand-up and connect your laptop .
The steps are not really that hard , here we go:
1- We need to install the printer driver, mine is HP , so i use
sudo apt-get install hplip
and then ran hp-doctor to fix any missing packages.
( for my case i had to add the foo2xqx driver , followed the instructions here )
for my printer (P1005) i installed printer-driver-foo2zjs through apt-get
2- The server software
sudo apt-get install cups
then  to enable the remote web administration , use the command
sudo cupsctl --remote-admin
finally , restart the service , use : sudo service cups restart
finally , the admin interface is located at : https://localserveraddres:631
Note: You might want to add your user  to the lpadmin group for admin access to the CUPS web interface , specially if you’re not using the root user for administering your linux box . the commmand is
sudo usermod -a -G lpadmin username

Scan Server

I’ve done  this before . However, there is always room for making the process easier by doing a bit of research before going all the way. I found this ubuntu guide and  this guide from debian wiki as well.
Following the debian’s guide, I’ve installed the three packages sane-utils ,libsane and inetutils-inetd,then used the command:
sudo nano /etc/default/saned
and replaced the "no" by a "yes" here
# Set to yes to start saned        
RUN=yes
Also added this line
to /etc/inetd.conf , also by nano
sane-port stream tcp nowait saned.saned /usr/sbin/saned saned
added the saned to the lp group
sudo usermod -a -G lp saned
and finally append the access list to /etc/sane.d/saned.conf
192.168.0.0/24
Of course, this is the network Id of your internal network.
Some more info from Ubuntu’s guide :
sudo nano /etc/systemd/system/saned.socket
and add the following text
# Defaults for the saned initscript, from sane-utils

# To enable under systemd please read README.Debian
# Set to yes to start saned under SysV
RUN=no

# Set to the user saned should run as
RUN_AS_USER=saned
cat /etc/systemd/system/saned.socket
[Unit]
Description=saned incoming socket

[Socket]
ListenStream=6566
Accept=yes
MaxConnections=1

[Install]
WantedBy=sockets.target
One more file to create
sudo nano /etc/systemd/system/saned@.service
and fill with
[Unit]
Description=Scanner Service
Requires=saned.socket

[Service]
ExecStart=/usr/sbin/saned
User=saned
Group=saned
StandardInput=null
StandardOutput=syslog
StandardError=syslog
# Environment=SANE_CONFIG_DIR=/etc/sane.d SANE_DEBUG_DLL=255
the last command to put it in the startup is
sudo systemctl enable saned.socket
A reboot will also do the same effect. after that you can use the tool from my earlier post or http://sanetwain.ozuzo.net/ or whatever tool you find interesting from windows to test your scanner remotely. Please share yours here if you like.

References
http://dimabobkov.blogspot.com.eg/2015/11/install-and-configure-raspbian-jessie.html
http://www.howtogeek.com/167195/how-to-change-your-raspberry-pi-or-other-linux-devices-hostname/
http://askubuntu.com/questions/45607/how-to-mount-partition-permanently
http://www.cyberciti.biz/faq/linux-finding-using-uuids-to-update-fstab/
https://wiki.openwrt.org/doc/uci/transmission

No comments:

Post a Comment

I'd like to read your comments

Popular