Skip to main content

Raspberry Pi 3 Headless Server With SSH

If you wish to make a standalone router, file server, or satellite weather station, then you need a little computer to make things happen.  At this time, the most popular embedded Linux machine is the Raspberry Pi.  It is a delightful little design - tiny and very useful.

The default system is Raspbian, which is loosely based on Debian.  This is excellent.  Years ago, I tried a Beaglebone Black and it came with a cripple version of Angstrom Linux which I didn't like and the board is consequently lying somewhere in my junk box.

The Raspbian system is aimed at clueless newbies and the ssh daemon is disabled by default.  To use it as an embedded server, without having to plug in a keyboard and screen, you need to add one line to a configuration file, before you plug the SD card into it.  Here is how to do all that.

Get a Pi and a SD Card Image

Get your RPi3 from here:
https://www.sparkfun.com/products/13826

Download a Raspbian image zip file from here:
https://www.raspberrypi.org/downloads/

Open a terminal and unzip with:
$ ark —batch filename.zip

That will take a loooong time…
(On Linux machines, you probably have to do this on the command line.  A graphical tool will very likely run out of memory and crash.  Just double clicking it will work fine on a Mac since they usually have enough RAM installed.)

Become super user:
$ su -
password


Write the img file to a miniature SD card:
# dmesg (to see what is going on, then insert SD card)
# dmesg (again, to see what is the device name)

# dd if=filename.img of=/dev/mmcblk0p bs=1M
(If the device is busy, it was probably unhelpfully mounted - unmount it)

or on a Mac:
$ sudo dd if=filename.img of=/dev/disk2 bs=1000000 

Ensure that the buffers are flushed:
# sync

Make a Headless Pi with the SSH Daemon

If necessary, re-insert the SD card and mount the root directory (don’t bother with the boot directory).
# cd /run/media/username/root/etc
# vi rc.local


Insert mode:
i

Go to the bottom and just above the exit statement add:
systemctl start ssh

Save the file:
[esc]wq

Flush the disk file buffers:
# sync

Umount and Eject the card.

First Login

Now when you hook the Pi to your router, it will get an IP address via DHCP and then run sshd automatically the way the Linux gods intended it to be.

You can then log in with for example:
$ ssh pi@192.168.1.100
raspberry
$


Change the password:
$ passwd
raspberry
newpassword
newpassword

Expand the root filesystem to use all of the SD card

Since this is a new device, you need to expand the file system to fill the whole SD card:
$ sudo raspi-config
password

Now do Update followed by Advanced, Expand Filesystem.  Then do Finish, Reboot, Yes.

Solid State File Server

With four 256 GB USB flash memory widgets plugged in, you can make a 1 TB solid state file server for about 1100 Dirhams - something that was unimaginable just a few years ago.

A file server doesn't have to be fast.  It is limited by the network speed, not the processor.  So a little Rpi makes a very cost effective file server.

So far, I managed to get only two 256 GB Sandisk widgets.  They came in perfectly idiotic packages, so I had to break all the plastic off to get them to fit in the USB sockets.  For protection, I wrapped one layer of self vulcanizing tape around them.  I don't know what the clowns who designed the little enclosures were thinking, but it was clearly form over function - now it is function over form...

I always prefer doing things the simple way, so I formatted them with ext4 and mounted them using /etc/fstab in /mnt/sda1 and /mnt/sdb1 like this:
$ sudo fdisk /dev/sda1
-t 83
-w

$ sudo mkfs.ext4 -L sda1ext4 /dev/sda1
y


$ sudo nano /etc/fstab /dev/sda1 /mnt/sda1 ext4 defaults,noatime 0 1

$ sudo mount -a

...and ditto for the other one.


I have never managed to figure out how to mount a disk so that a common user can write to it.  My workaround is to make a directory on the thing and assign the user name and group to that, so now I have /mnt/sda1/dataa and /mnt/sdb1/datab and chowned them to pi:. $ sudo mkdir -p /mnt/sda1/dataa
$ sudo chown pi: /mnt/sda1/dataa

So the access problem is solved without having to read another manual on disk mounting and with that, I now have 512 GB of online solid state storage, accessible over ssh and scp.

Heat

These Sandisk USB watchammacallits get very hot and there are long stories on the Sandisk forums about heat problems.  So removing them from their plastic packaging is actually a good idea, since that improves the air flow over the chips. The good news is that most people say they last for years, despite the heat.

Rsync Backup Script

I made a RSA key file with ssh-keygen and uploaded it with ssh-copy-id, as described here https://www.ssh.com/ssh/copy-id

The IP address of the Rpi was added to /etc/hosts, so I don't have to keep typing it in.

One's natural instinct is to make a backup script that includes all the files that one needs to backup - that is wrong!

The trick with a backup script, is to keep it simple and include everything in your home directory and then exclude a few generic things.   That way, the script is maintenance free and will always work, irrespective of how you move files around.

My Macbook rsync backup script now looks like this:
#! /bin/bash
rsync -avze ssh --progress --delete --max-delete=10 --max-size=20M --exclude '.Trash'  ~/. pi@rpi:/mnt/sda/dataa/

The max-delete protects against catastrophes and max-size prevents making backups of large ISO files and movies, since those things can always be downloaded again from wherever they came from.

Secure Shell SSH on Windows

Note that Windows 10 now finally supports OpenSSH, so you could also connect securely to a sshd server with sftp from the latest Win10, but not from Win8.1 or Win7.

Deduplication with Hard Links

Once you start to save backups, you will rapidly accumulate duplicate files on the server.  You can eliminate these with the hardlink utility and regain many gigabytes of storage space:
$ hardlink -c directoryname

A hard link is an additional directory entry for the same file.  When you delete hard links, the file will only disappear, once the last hard link is deleted.  This is much better than soft links, where you can delete the file, leaving a bunch of broken links all over the place, with no easy way to clean up the litter.  You can perhaps think of hard links as smart links and the other as soft in the head links.


La voila!

Herman

Comments

Popular posts from this blog

Parasitic Quadrifilar Helical Antenna

This article was reprinted in OSCAR News, March 2018:  http://www.amsat-uk.org If you want to receive Satellite Weather Pictures , then you need a decent antenna, otherwise you will receive more noise than picture. For polar orbit satellites, one needs an antenna with a mushroom shaped radiation pattern .  It needs to have strong gain towards the horizon where the satellites are distant, less gain upwards where they are close and as little as possible downwards, which would be wasted and a source of noise.  Most satellites are spin stabilized and therefore the antenna also needs circular polarization, otherwise the received signal will flutter as the antennas rotate through nulls. The helical antenna, first proposed by Kraus in 1948, is the natural solution to circular polarized satellite communications.  It is a simple twisted wire - there seems to be nothing to it.  Various papers have been published on helix antennas, so the operation is pretty well understood. Therefore,

To C or not to C, That is the Question

As most would know, the Kernighan and Ritchie C Programming Language is an improved version of B, which is a simplified version of BCPL, which is derived from ALGOL, which is the Ur computer language that started the whole madness, when Adam needed an operating system for his Abacus, to count Eve's apples in the garden of Eden in Iraq.  The result is that C is my favourite, most hated computer language , which I use for everything. At university, I learned FORTRAN with punch cards on a Sperry-Univac, in order to run SPICE, to simulate an operational amplifier.  Computers rapidly lost their glamour after that era! Nobody taught me C.  I bought the book and figured it out myself. Over time, I wrote a couple of assemblers, a linker-locator, various low level debuggers and schedulers and I even fixed a bug in a C compiler - not because I wanted to, but because I had to, to get the job done!   Much of my software work was down in the weeds with DSP and radio modems ( Synchronization,

Weather Satellite Turnstile Antennas for the 2 meter Band

NEC2, 2 m band, 146 MHz, Yagi Turnstile Simulation and Build This article describes a Turnstile Antenna for the 2 meter band, 146 MHz amateur satcom, 137 MHz NOAA and Russian Meteor weather satellites.  Weather satellite reception is described here .  A quadrifilar helical antenna is described here .   Engineering, is the art of making what you need,  from what you can get. Radiation Pattern of the Three Element Yagi-Uda Antenna Once one combine and cross two Yagis, the pattern becomes distinctly twisted. The right hand polarization actually becomes visible in the radiation pattern plot, which I found really cool. Radiation Pattern of Six Element Turnstile Antenna Only a true RF Geek can appreciate the twisted invisible inner beauty of a herring bone antenna... Six Element Turnstile Antenna Essentially, it is three crosses on a stick.  The driven elements are broken in the middle at the drive points.  The other elements can go straight throug