How to set up SSH two-factor authentication for Raspberry Pi

There is a very good step by step tutorial on how to set up two-factor authentication for your Raspberry Pi in the included video. I have the step by steps commands listed below.

Two-factor authentication

Go to the terminal and enter this command:

sudo apt update && sudo apt upgrade && sudo apt dist-upgrade

Enable SSH in your raspberry pi config file

Go to the terminal and enter this command to enable the challenge file for SSH. You need to change the # Authentication from no to yes:

sudo nano /etc/ssh/sshd_config

Then hit cntrl x then y then enter to save.

Then you need to restart SSH. Go to the terminal and enter this command:

sudo systemctl restart ssh

Now install Google Authenticator for your Smartphone

Now install the PAM module for your Raspberry Pi. Go to the terminal and enter this command:

sudo apt install libpam-google-authenticator

Now run the Google Authenticator on the command line. Go to the terminal and enter this command:


Then write down the emergency codes – just in case you need them later.

Then enter YES, YES, NO, YES

Go to the terminal and enter this command:

sudo nano /etc/pam.d/sshd

While in the file, add this command after “@include common-auth”

auth required

Then you need to restart SSH. Go to the terminal and enter this command:

sudo systemctl restart ssh

When I use Putty to SSH into my RPI and this works as advertised.

However, when I use VNC Viewer, it does not. I am looking for a solution to this and when I have one I will edit this post.

Raspberry Pi Zero W – Day 2 – Benchmarks

How to Benchmark Your Single-Board Computer

I would like to establish a SOP (standard operating procedure) or  “methodology” going forward so all of you can create your own results. In order for this to be a fair test the following criteria were observed.

  • All CPU and memory tests conducted using Sysbench and/or command line.
  • All Single-Board computers were not contained in a case and used “bare”.
  • All tests using the latest version of that specific systems preferred software.
  • All tests were at ambient temperature before testing began.
  • I accessed the Single-Board computers over an SSH connection.
  • No desktop / X session started unless the tests required the desktop.
  • All test results are a combination of the tests being run 3 times and the mean average was used for the final result.

What is Sysbench

Sysbench is a benchmark suite which allows you to quickly get an impression about system performance which is important if you plan to run a database under intensive load. I will explain how to benchmark your CPU with Sysbench.

Installing Sysbench

From a terminal screen on Debian/Ubuntu/Mint/Raspbian, Sysbench can be installed as follows:

sudo apt-get install sysbench

If you want to learn more about the program you can look at the manual for Sysbench to learn more about its parameters.

man sysbench

CPU Benchmark

You can benchmark your CPU performance as follows:

If you have a single core processor, like a Raspberry Pi Zero, you can use this command:

sysbench –test=cpu –cpu-max-prime=20000 run


If you have a multicore cpu you can use this command:

sysbench –test=cpu –cpu-max-prime=20000 run –num-threads=4


RAM Benchmark

sysbench –test=memory –memory-block-size=1M –memory-total-size=10G run



Terminal command line benchmark testing

Integer calculation performance test with  one-line command

time $(i=0; while (( i < 1234567 )); do (( i ++ )); done)

This will return the the time required to crunch the integers between 0 to 1234567.



RAM speed testing

There is no direct method to benchmark a RAM and generally RAM speed  denotes RAM clock speed. It is unnecessary and not conclusive to do this test but this may be considered as an experiment. As you can benchmark this data with changes you do to your system or compared to other systems. 

tmpfs is a RAM based super fast file system, something like a ramdisk, so by doing a read write speed test on a tmpfs mounted folder will give a rough idea about RAM speed. So, let’s have a look at commands below.

mkdir RAM_test
# mount the tmpfs filesystem
sudo mount tmpfs -t tmpfs RAM_test/
cd RAM_test

# write to RAM test
dd if=/dev/zero of=data_tmp bs=1M count=512
# read to RAM test
dd if=data_tmp of=/dev/null bs=1M count=512

Here are the results for the Raspberry Pi Zero W. I achieved around 35 MB/s write speed and 79 MB/s read speed with a 512MB of DDR2 SDRAM.


On my main PC look at the result ! It’s incredibly fast ! I achieved around 4.6 GB/s write speed and 8.0 GB/s read speed with a 16GB 2400MHz DDR4 RAM.


Time to clean up what you just did.

cd ..
# umount the tmpfs filesystem
sudo umount tmpfs -t tmpfs RAM_test/
# delete the directory you created
rm -r RAM_test

NOTE: My main computer is an I5 with 16GB DDR 4 ram at 2400MHz
It is a dual boot with Win 10 and Linux Mint

More testing coming up!


%d bloggers like this: