How Do You SSH into a Raspberry Pi 3 from a Windows Computer That Is on the Same Network?

Problem scenario
You want to use Putty from a Windows 7 or Windows 10 workstation to connect to a Raspberry Pi 3 on the network. You want to connect via a command prompt (not with a GUI).  What do you do?

Solution
On the Raspberry Pi do these three steps:
1.  Change password for the pi user or create a new user.
2.  Find the IP address by using "ifconfig" with no quotes in a command terminal.  (You can use "ip addr show" if you prefer.)
3.  Go to the Raspberry button in the upper left hand corner, go to Preferences -> Raspberry Pi Configuration.  For SSH choose "Enabled."
4.  On the Windows machine, open Putty.  If you don't have it, you can download it from here.  From the Windows machine, follow the next three steps.
5.  Type in the IP address of the Raspberry Pi
6.  Click "open"
7.  Connect as normal

How Do You Troubleshoot the Error “No package foobar available”?

Problem scenario
You are running "sudo yum install foobar" but it is not working.   You are trying to install a package on a RHEL server, but it is not available from the configured repositories.  You notice that many packages you normally install are not available.  What should you do?

Solution
Run this command:
sudo yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional

FFR
To find the number of packages available to you in the configured repository (or repositories), run this command:
sudo yum list available | nl | tail -n 1 | awk '{print $1}'

To learn more about yum commands, see this PDF that RedHat.com provides.

How Do You Set up HAProxy on a Linux Server?

Problem scenario
You have some web servers that you want a new HAProxy server to distribute traffic to.  You have an Ubuntu or Debian Linux server that you want HAProxy installed on.  You want HAProxy to be a load balancer. What do you do?

Solution
Prerequisites

You have at least two web servers set up and you know their IP addresses (either internal or external).  If you do not have these, you may want to see one of these four articles:

How Do You Install Apache Web Server on Ubuntu Linux?
How Do You install Apache Web Server with CentOS/RHEL/Fedora?
How Do You install Nginx on a Debian/Ubuntu Server?
How Do You install Nginx on a CentOS/RHEL/Fedora Server?

You have a third Linux server which will receive the HAProxy installation; this server can have as little as 1 GB of RAM and just one basic processor.  You may need a more powerful server if it will support considerable traffic, but for testing it will be fine.

Procedures
These steps are to be done on the server that will get the HAProxy installation.

1.  If you are using an Ubuntu or Debian server, run these commands:
sudo apt -y update
sudo apt-get -y install haproxy

If you are using a CentOS/RHEL/Fedora server, run these commands:
sudo yum -y update
sudo yum -y install haproxy

2.a.  Modify the main configuration file with this command:
sudo vi /etc/haproxy/haproxy.cfg

2.b.  Determine if you have a CentOS/RHEL/Fedora server (a RedHat derivative) or an Ubuntu/Debian server.  Follow the step 2.b.i or 2.b.ii for your distribution only (do not do both):

2.b.i  For CentOS/RHEL/Fedora, find the "frontend main" section.  Replace the "5000" with "80".  With an indentation to match the other stanzas underneath "frontend main" insert this stanza:
    option                      forwardfor

For the "backend app" section find the stanza with "app1". Replace the 127.0.0.1 with the internal or external IP address of one of the web servers.  Replace the 5001 value with "80".    

Find the stanza with "app2". Replace the 127.0.0.1 with the internal or external IP address of one of the web servers.  Replace the 5002 value with "80".  Skip to 3.

2.b.ii  For Ubuntu or Debian, do the following.  To have HAProxy distribute traffic to different web servers, insert these stanzas at the bottom of the above file (from "frontend firstbalance to "option httpchk"):

frontend firstbalance
        bind *:80
        option forwardfor
        default_backend webservers

backend webservers
        balance roundrobin
        server webserver1 x.x.x.x:80
        server webserver2 y.y.y.y:80
        option httpchk

2.c.  Replace x.x.x.x with the IP address (either internal or external) of the first web server.  Replace y.y.y.y with the IP address (either internal or external) of the second web server.  Save the changes.

3.  Verify you have no intermediate firewall, or AWS Security Group, or Azure NSG, or Google firewall rule, between the HAProxy server and the IP address it is trying to reach.  Port 80 must be open from the HAProxy server to the other servers.  Remember if you are reaching internal IP addresses, use the internal IP address of the HAProxy server.  If you are configuring HAProxy to use external IP addresses, use the external IP adress of the HAProxy server.  To find your external IP address, use this command (assuming you have access to the internet): curl icanhazip

To find your internal IP address use this command: ip addr show | grep inet

4.  Restart HAProxy.  If you have a Debian/Ubuntu server, use this command:
sudo /etc/init.d/haproxy restart

Otherwise use this command:
sudo service haproxy start

How Do You Fix a Python Program That Returns an Error “…subprocess.py … in check_output”?

Problem scenario
You are trying to use subprocess and check_output in Python to run raw Bash/shell/Linux commands.  

Your Python program has a line like this:
subprocess.check_output("/usr/local/bin/coolprog arg1 /path/to/file.txt arg3")

You get this error when you run the program:

 File "/usr/lib/python2.7/subprocess.py", line 566, in check_output

What do you do?

Solution
This solution only applies if the Bash command is constructed from known good input.  If the command that the subprocess invocation is constructed from is an external source, this solution would inadvisable; we do not recommend you adapt this solution to something that could be susceptible to malicious code injections.

The above subprocess.checkoutput line works for a single-word Linux command.  For commands with more involved syntax, you must change it to include "shell=True" after a comma and space; you also need a .split() at the end of the closing parenthesis above.  Here is an example of how to properly use check_output:

subprocess.check_output("/usr/local/bin/coolprog arg1 /path/to/file.txt arg3", shell=True).split()

# If you want to learn more about the safety concerns of subprocess and shell=True, see this link.

How Do You Get Raspberry Pi to Use a USB Drive?

Problem scenario
You are trying to use a USB stick with your Raspberry Pi.  But you get errors you receive say things like "operation not permitted" and "target is busy."  You want to create new directories and files on this thumb drive.  What do you do?

Solution
1. Remove the USB stick.
2.  Insert it.  Do not choose the GUI prompt to use File Manager.  
3.  With a command prompt, find the gid and uid of the user you want to be able to access to the USB drive.  If you know the username, run this command:

id jdoe # where jdoe is the username

4.  Use the following command where "foobar" is the name of the directory you want to refer to when you read/write to the USB drive, "1001" is the gid of the user above and "1000" is the uid of the user above.

sudo mount -o remount,gid=1001,uid=1000 /media/pi/foobar/

# Without modifying the fstab, this mounted directory may be available after a reboot of the Raspberry Pi!

How Do You Troublshoot the Error “snappymodule.cc:31:22: fatal error: snappy-c.h: No such file or directory” when Trying to Install Apache Parquet?

Problem scenario
When trying to install Apache Parquet on Ubuntu, you get this error:

"Running python-snappy-0.5.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-SIHL_T/python-snappy-0.5.1/egg-dist-tmp-O8UnkU
WARNING: '.' not a valid package name; please use only .-separated package names in setup.py
package init file '__init__.py' not found (or not a regular file)
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
snappymodule.cc:31:22: fatal error: snappy-c.h: No such file or directory
compilation terminated.
error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
ubuntu@ubuntuf1:/opt/parquet-1.2$ find . -name snappymodule.cc
ubuntu@ubuntuf1:/opt/parquet-1.2$ sudo apt-get install python-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-dev is already the newest version (2.7.11-1).
0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded."

What should you do?

Solution
Assuming you are running Ubuntu Linux, run this command to satisfy a dependency of Apache Parquet:
sudo apt-get -y install libsnappy-dev

How Do You Get to the First Character in a Linux Command Prompt?

Problem scenario
You are trying to run very long, complex Linux commands.  There are many case-sensitive flag options and convoluted DNS names.  It takes time to hold the left arrow to go to the beginning of the command.  Sometimes you want to comment out a line with a "#" at the beginning of the line as you draft these Linux commands.

Solution
Use ctrl-a to get to the first character of the command.

Conversely you may want to get to the end of the line immediately.  Use ctrl-e to get to the last character of the command.

Remember that "#" (with no quotes) will comment out whatever is to the right of it.  Therefore you can draft commands like this:

#Let me try to draft something with different flag options.  I can always use Ctrl-A to get to the first line and Ctrl-E to the end of this long line before I press enter to run the command.

Ctrl-c will allow you to cancel out of a command without running it.

How Do You Update the BIOS of an HP Computer When the Option You Need Is Grayed Out?

Problem scenario
You turn on an HP computer (e.g., a desktop or laptop) and press Esc to go to the Startup Menu.  You then press F10 or use the down key and press enter to get to the BIOS menu.  When you are there you see the option you need "Update BIOS Using Local Media" is grayed out.  You entered administrator-level credentials successfully.  You have not other credentials to log into this HP startup menu.  What do you do to update the BIOS?

Solution
Log in as a guest user.  For some reason a guest user may be able to have see clickable blue text "Update BIOS Using Local Media."  This solution can work.

How Do You Manage (List, Resume or Terminate) Suspended Linux Commands?

Problem scenario
You have started some commands then used Ctrl-z while they were still processing.  You want to see which jobs have been suspended.  You may want to terminate or run the jobs. What do you do?

Solution
Use the builtin Linux command "jobs" like this:

jobs -l

# Sample output may look like this:

[1]- 26830 Stopped                 ping -c 100 8.8.8.8
[2]+ 26831 Stopped                 ping -c 99 8.8.8.8

To resume the lowest job in the output of the above command, use this command with no arguments:

fg

# fg will resume the job with the "+" sign in the list from the "jobs -l" command.
# fg can be used to start specific jobs and not necessarily the bottom job when it has the correct argument.  

To terminate a job listed in "jobs -l" you can use this command:

disown <pid> # where <pid> is the number listed before the word "Stopped" in the output of "jobs -l"

You can also refer to the numbers such as [1] and [2] as they appear in the left hand column in the output of "jobs -l".  To do this use the %x format where "x" is the number that is in the brackets "[]" in the left hand column of the output of "jobs -l".

You can use fg or bg to resume the suspended jobs.  Based on this integer in the brackets "[]" in the left hand column of the output of "jobs -l", you can use the % syntax like this:

fg %1  #this will resume the "ping -c 100 8.8.8.8" job in the foreground

or

bg %1 #this will resume the "ping -c 100 8.8.8.8" job in the background

# The disown command is a builtin command. It can also refer to jobs with the %x syntax like the fg and bg examples above.

How Do You Enable IP Version 4 Forwarding on an Ubuntu Server?

Problem scenario
You want to enable IP version 4 forwarding on an Ubuntu server permanently.  How do you do this without rebooting?

Solution
1.  Run this command:sudo sysctl -w net.ipv4.ip_forward=1

2.  Modify the /etc/sysctl.conf file. Use "sudo vi /etc/sysctl.conf"

Uncomment out this stanza:

net.ipv4.ip_forward=1

3.  Save the changes.  You are done.