Where Do You Find the IP Address from Most Recent Login on a Linux Server?

Problem scenario
You want to know where the Linux users are logging on from (e.g., for security and configuration reasons).  You want to know the IP addresses of their desktops.  Where do you find the IP address from most recent login on a Linux server?

Solution
To see the most recent login session details (including IP address), run this command:

last

After you press enter you'll see the most recent logins.  To find the source IP address of the users that are currently logged into a Linux server, run this command:

last | grep "still logged in" | awk '{print $3}'

How Do You Troubleshoot a False “State” Value in nmap Results?

Background
For troubleshooting networking issues with a Linux/Unix server, the nmap utility is extremely useful.  For Windows with PowerShell version 3, there is a script can help you almost as much as nmap; see this posting if you are interested.  For newer versions of PowerShell, use the Test-NetConnection command.  

Problem scenario
You use nmap to test a port on an IP address.  The results show the "State" as closed, but you know there are packets flowing through the IP address on this port.  How do you troubleshoot nmap with its "State" result is discrepant with other diagnostics?

Solution
If the IP address belongs to a server that has a VPN connection, there could be an apparent false result from nmap.  Some VPN tunnels are known to make the nmap results show the state of the IP address for a given port as closed.  This is tantamount to nmap reporting that there is no intermediate blockage to the remote server over the given port and that no packets are flowing through this socket.

Other VPNs on remote servers make the nmap show the state as "filtered" as the port you are testing is blocked by the VPN tunnel.  If you know there are TCP/IP packets from the IP address on the given port and you want nmap to accurately report this, use a VPN tunnel configured in such a way that the nmap command will report the "state" correctly.  Alternatively see if the VPN tunnel can be turned off for your nmap testing needs.

How Do You Connect to a Specific Postgres Database without a SQL Front End?

Problem scenario
From a Linux command prompt (e.g., Linux terminal) you want to connect to a specific Postgres database.  How do you create a table or issue SQL commands to a specific Postgres database from the back-end (the Postgres server itself)?

Solution
1.  First enter the Postgres command prompt by running these two commands:

sudo -i -u postgres
psql

2.  Assuming the database's name is cooldb, run this command:

\connect cooldb;

3.  Run your SQL commands. For example:

create table veryneat(id int, name varchar(40));
insert into veryneat values(1, 'words');

How Do You Know If Your Linux Server Can Support a Docker Installation?

Problem scenario
You want to install Docker on Linux.  How do you determine if the VM or physical server with Linux meets the minimum requirements for installing Docker?

Solution
Run this script:

#!/bin/bash
# Written by continualintegration.com
echo "This will test if your Linux server is ready for Docker."
i=0;

os=$(uname -m | grep -i x)
if [ -z "$os" ];
then
  echo "*** FAILURE ***"
  echo "The OS is 32 bit.  It will not work for Docker."
  i=$((i+1))
  echo "Proceeding to next test"
else
  echo "The OS is 64 bit"
fi

a=$(uname -r)
b=$(echo $a | awk -F  "." '/1/ {print $1}')
c=$(echo $a | awk -F  "." '/1/ {print $2}')
if [ $b -lt 3 ]
then
  echo "Kernel is not high enough"
  i=$((i+1))
else  #This is evaluated if Kernel is 3.x or 4.x or higher
  if [ $b -eq 3 ]
  then
    if [ $c -lt 10 ]
    then
      echo "*** FAILURE ***"
      echo "Kernel is not high enough"
      echo "Proceeding to next test"
      i=$((i+1))
    else
      echo "Kernel appears high enough."
    fi
  else
    echo "Kernel appears high enough."
  fi
fi

d=$(iptables -V | awk -F  "." '/1/ {print $2}')
if [ $d -ge 4 ]

then
  echo "IP tables is high enough"
else
  echo "*** FAILURE ***"
  echo "IP tables is not high enough."
  echo "Proceeding to next test"
  i=$((i+1))
fi

p=$(which ps)
if [ -z "$p" ];
then
  echo "*** FAILURE ***"
  echo "You do not have an executable ps command.  Install procps or something else."
  echo "Docker needs an executable ps command."
  echo "Proceeding to next test"
  i=$((i+1))
else
  echo "You have an executable ps command."
fi

f=$(xz --version | grep xz | awk '{print $4}' | awk -F  "." '{print $1}')
g=$(xz --version | grep xz | awk '{print $4}' | awk -F  "." '{print $2}')
if [ $f -ge 5 ]
then
  echo "The version of xz utils is high enough"
  echo "Docker test script is complete."
  echo $i " tests/checks failed."
  if [ $i -eq 0 ]
  then
    echo "Docker can be installed as long as your OS has 'a properly mounted cgroups hierarchy' taken from https://docs.docker.com/engine/installation/binaries/#install-daemon-and-client-binaries-on-linux"
  fi
  exit
fi

if [ $f -eq 4 -a $g -ge 7 ]
then
  echo "The version of xz utils is high enough"
else
  echo "*** FAILURE ***"
  echo "The version of xz utils is not high enough."
  i=$((i+1))
  echo "Docker test script is complete."
  echo $i " tests/checks failed."
  if [ $i -eq 0 ]
  then
    echo "Docker can be installed as long as your OS has 'a properly mounted cgroups hierarchy' taken from https://docs.docker.com/engine/installation/binaries/#install-daemon-and-client-binaries-on-linux"
  fi
fi

# If you are interested in a list of Docker books, see this link.
# If you want instructions for installing Docker in different public clouds or on different distros of Linux, see this posting.
# For a very different script that does something similar, you may want to see this one on GitHub.

How Do You Know If Your Linux Kernel Meets the Minimum Requirements for Docker?

Problem scenario
You want to install Docker, but you want to be sure that the kernel is high enough to be supported.

Solution
The minimum kernel version is stated on Docker's website.  As the spring time of 2017, run this script to find out if your kernel version is high enough:

a=$(uname -r)
b=$(echo $a | awk -F  "." '/1/ {print $1}')
c=$(echo $a | awk -F  "." '/1/ {print $2}')
if [ $b -lt 3 ]
then
  echo "Kernel is not high enough"
  i=$((i+1))
else  # This is evaluated if Kernel is 3.x or 4.x or higher
  if [ $b -eq 3 ]
  then
    if [ $c -lt 10 ]
    then      
      echo "Kernel is not high enough"
    else
      echo "Kernel appears high enough."
    fi
  else
    echo "Kernel appears high enough."
  fi
fi

# For a more thorough test to see if your OS can handle Docker, see this article.
# For a variety of directions on how to install Docker (e.g., on CentOS/RHEL, SUSE, or Ubuntu in AWS, Azure or GCP), see this posting.

How Do You Get Passed an Error about an Environment Variable When Installing etcd on Linux?

Problem scneario
According to Coreos.com, etcd is  "[a] distributed, reliable key-value store" to be used on  "a distributed system."  You are trying to install etcd, but you get an error about an environment variable and invalid syntax.  

For example, you try to run this script:
./etcd

But you get this output:  

"2017-03-31 19:22:19.332257 I | flags: recognized and used environment variable ETCD_VERSION=2.2.0
2017-03-31 19:22:19.332385 C | etcdmain: invalid value "2.2.0" for ETCD_VERSION: strconv.ParseBool: parsing "2.2.0": invalid syntax"

What should you do to install etcd?

Solution
Reboot the server.  If the problem still happens, ask the systems administrator if you can eliminate the etcd_version environment variable from the server for the duration of the installation of etcd.

How Do You Determine a MAC Address of an IoT Device (without Network Administrator Access to a Router)?

Problem scenario
You have a device (e.g., some IoT gadget such as an EZviz camera) that can connect to a network (e.g., via WiFi).  But you do not have access to the administration (e.g., back end) of the router itself. You want to learn the IoT device's MAC address (e.g., for a third party that can grant the device WiFi access).  If you administered the router, you could find the MAC address of devices that could connect to the router.  You tried looking at the labels of the physical IoT device and inspecting the paperwork (documentation and/or instruction manual) that came with the device.  You still do not know its MAC address.  Like all IoT devices, it can connect to a TCP/IP network (e.g., the internet).

Solution with an Android tablet/phone
Connect the Android tablet/phone to the same network the device in question is connected to.  On your Android tablet/phone, install Fing from the Google Play Store.  Look at the MAC addresses of the devices that are on the network in Fing.  Connect the device to the network and refresh Fing (e.g., by clicking a semi-circle arrow in the upper right-hand corner).  Find the device that recently connected to the network.

Solution with a Windows computer
Connect the Android tablet/phone to the same network the device in question is connected to.  On your Android tablet/phone, install Find MAC Address (or if you need a business edition, try this link) by Lizard Systems.  Search for a range of IP addresses on the network to find the device in question.  Find the device that recently connected to the network.  If you are not sure about the device in question, narrow your range or do A/B testing.  For A/B testing turn the device off then do a scan with the Lizard Systems' Find Mac Address for an "A" test; turn the device on then do the scan via the Lizard Systems' Find Mac Address for a "B" test).

How Do You Configure an Ezviz Mini 0 Camera for the First Time?

Problem Scenario
You want to configure an Ezviz Mini 0 camera for the first time.  How do you set it up?

Solution
Warning:  The lowest cost plan for ezviz cloud storage is $59.99.  However you do not have to purchase the cloud storage to use the camera.

1.  Connect the camera to a power outlet.  
2.  Hold the reset button for 10 seconds.
3.  Go to your Android or iOS device.  
4.  Connect your Android or iOS device to a WiFi network.
5.  Install the Ezviz app.
6.  Open your Ezviz app.
7.  Follow the prompts to set up a new camera.  When prompted for the device password, use the "Verification code" found on the bottom of the camera itself.
8.  If you are having trouble, see this link for more information.

How Do You Protect Your Privacy When You Are Traveling?

Updated on 8/1/21

Problem scenario
You want to travel and protect your privacy.  You use a cell phone, smart phone, and/or laptop like anyone else.  What can you do to enhance or preserve your privacy?

Solution
There are three parts to this solution.  The first part involves items you would bring with you.  The second part is for items that help secure your home when you are away.  The third part is a list of external articles to help educate yourself about privacy.

Part 1:  Products and Services to Protect Your Laptop

Here are 18 items to bring with you when you travel:

1.  A laptop lock.  Smash and grabs are easy for a thief.  A laptop lock can deter this.

2.  A security camera.  Set up an EZVIZ camera with a WiFi connection to watch your hotel room.  This one has a motion detector ability to make playback review a snap; if you are traveling by yourself, you will know when there should movement in your room.  There is a timeline in the Ezviz application to quickly see when activity was captured.  A web browser or an Android app allow you to view the playback.

3.  A USB battery bank.  If you do not trust the hotel to keep the electricity going, you may want to purchase a travel battery for your EZVIZ camera.  These battery banks can power a trusted WiFi source.  While traveling, you may find USB charging stations in a number of convenient locations.  But beware! CNN recommends that you do not use public charging stations to protect your data from being stolen.

4.  A VPN tunnel (sometimes referred to as a proxy service or an IP masker) as some WiFi networks are not trustworthy.  Three specific options include NordVPN, PureVPN, and VyprVPN. But there are many other choices you can make. Bruce Schneier discusses the complexity and unknowns of choosing the right VPN here. To pick the best one for you, your needs and budget, you may read one or all of these seven links:

5.  A comprehensive anti-virus with software firewall for your laptop. For just the anti-virus, we have had a good experience with ESET. ESET makes antiviruses for Linux (but usually you do not need one for *nix OSes). ESET is available for Macs and Windows too.

6.  Complementary anti-spyware application (e.g., SUPER AntiSpwyare).  One anti-malware vendor is not enough for Windows devices (e.g., you need something beyond #5 above).  We recommend the professional edition of SUPER AntiSpwyare to save time over the long run.  But to save money the link above will give you the option to use the free version.

7.  Vaultz bags for your USB sticks.  These are good for plane trips if you fall asleep and want peace of mind.  

8.  A Doberman bag protector alarm (SE-0304OR).  These sound very loud if they are physically moved.  They are smaller than an orange and can be hidden in a suitcase bag on top of something valuable.  Some housekeepers at even fancy hotels are not trustworthy.  The sound is so loud that the batteries get drained almost immediately.  It is not overly useful in many  situations.  However for certain situations (e.g., putting your belongings in a storage facility without power or when you need to quickly leave a hotel room due to a policy with the hotel when your room is being serviced by the maid), it can be another line of defense. 

9.  The Ghostery plugin on your web browser.  

10.  A JetPack or hotspot with a reputable ISP.  Use an internet service you can trust.  Verizon is supposed to have a better subpoena policy than AT&T for notifying subscribers.  Verizon can have better coverage for some remote parts of the U.S. 

11. A money-stash side bag.  Like holsters these can be worn under clothing.  They allow you to keep your hotel and car keys and/or precious USB sticks with you if you go jogging or running.  Outdoor activity can make valuables drop out of your exercise clothes pockets.  This one that is linked is machine washable; a more affordable nylon money belt which is like a mini-fanny pack is probably washable too.  If you want to bring tissue packets and wear pocketless shorts or sweat pants, this allows you to keep things close-by when you leave your room.  It can be nerve-racking remembering times when you left your keys unattended.  Some fitness centers allow trusting visitors to hang keys unprotected in the open near the door.  People who do not want their cars stolen or otherwise want to prevent nosy intruders from going through their cars may not want to use such key racks.  A thief or unscrupulous nosy person could grab the keys without permission from the owner and identify the car using a button on the key chain to deactivate the alarm.  Often a sound will be audible and the headlights will flash upon pushing a button to unlock the car.  If you do not have a car alarm, the parts often cost less than $70 when purchased online.  A car alarm is advisable for protecting your privacy when you are on a road trip.  Vehicular break-ins are common in certain metropolitan areas.

12.  A headlamp.  If inclement weather causes an electrical blackout, you may need to put away certain papers quickly.  You may also be in danger by not having good visibility of what is at your feet or what is in your surroundings.  Being in an unknown building with different electronics plugged in can set you up for a temporary room power outage.  Some hotels have circuit breakers that will trip unexpectedly because guests plug in appliances at their disposal without knowing the limitations of the building.  A useful way of keeping your hands free while protecting your personal belongings in the event of unexpected darkness is to have a headlamp like this.  Quickly finding your way around a dark motel may be the difference between your preserving your privacy and protecting your personal security.  Opportunistic thugs frequent affordable motels in expensive big cities.  Another benefit is to see if you forgot something under a bed or behind a credenza.  Expect the unexpected when traveling; do not be dependent on others if/when there is shortage of flashlights.

13.  A locking suitcase that can be brought on to a plane as a carry-on.  At 9 x 21 x 14 inches, it is virtually the biggest suitcase that you can get and still be allowed as a carry-on for US flights.  Keeping an item as a carry-on allows you to keep an eye on your belongings and not get separated from your private items.  Please note that airlines may have different size limitations for luggage that is brought into the cabin.  The FAA regulations do not always govern every carrier.  Sometimes the airlines can be flexible with their own policies.

14.  A locking briefcase that is smaller than a suitcase may also be helpful.  The aluminum exterior would be difficult to cut.  It does not have the capacity of the suitcase above that is still allowable as a carry on however.  In the Silicon Valley, professionals do not dress formally when they conduct business.  They wear backpacks, shorts, and sandals.  For most companies in the Silicon Valley, it is inappropriate to go to an interview in a suit-and-tie.  Read that again: wearing a suit-and-tie to a software start-up interview in the Bay Area will usually reduce your chances of being hired.  You may not want to have a leather briefcase because many metropolitan businesses have officers or employees who support animal rights.

15.   Prepaid cell phones.  You may want to purchase them with cash from a retailer in person.  If you are not concerned about being traced to the point of purchase, you can buy them from Amazon.

16.   This item category is lightweight. Use www.duckduckgo.com 
or www.startpage.com as your search engines.  They are known for being better with privacy than Google.

17. To avoid blackmail attempts, be sure to cover the camera of your laptop when you are not using it. To read more, see this external posting entitled Why Is Everyone Covering up Their Laptop Cameras?. Webcam hacking is a problem; if you want to learn more see this posting.

18. You may want to bring your laptop with you when you leave the hotel room. Here is a bag that can hold laptops.

19. For your online passwords, you should change them regularly. To make strong passwords (that are difficult to remember) and change them frequently, you may need a password manager. Roboform is one such option that can be installed on a smartphone or a laptop.

Bonus:  For protecting yourself when you make a purchase online, you may want to read this article.

Part 2:  Privacy at Home When You Are Away
For your home you may want to purchase these items (rather than be locked into a home security service subscription with a 36-month commitment):

COOWOO ST30 Professional Wireless Smart Home Security Alarm System DIY Kit

Maximus Smart Home Security Outdoor Light & Camera

Nest Protect Smoke & Carbon Monoxide Alarm (great if you have pets)

Ring Wi-Fi Enabled Video Doorbell

Civil or criminal subpoenas often request bit-for-bit backups of USB sticks that pertain to a subject related to the  litigation or investigation.  If a hacker takes control of your computer, your devices may be the subject of a subpoena because of the damage he inflicted to others.  You  may want to have extra USB drives to ensure sequestration based on subject.  A hostile investigator or attorney will use any  facts he/she can against you.  You may want to purchase a USB splitter such as this with ample USB sticks to keep your files  segregated in case you are subpoeanaed.  You may want to label them to keep them separate.

Part 3: Learn about the Law
While the laws are only part of privacy (some aspects of privacy are best addressed using a different or preventative way), it is advisable to learn about the laws of your state. You may want to purchase a Nolo product to begin to learn about the law:

If your privacy has been violated or you have specific questions about the laws in a given state before you travel, you may want to hire a personal injury attorney (but please note that we do not warrant external websites or third party companies such as individual attorneys):

Part 4: Educate Yourself about Privacy in General
You may want to read these articles:​

October 11, 2020 update: This external article is about an Apple-Google project that deals with COVID-19 and privacy.

How Do You Check If a Variable in Ruby Is a Boolean?

Problem scenario
You want to determine if a variable is being assigned a non-string "true" or "false" data type.  That is, you want to distinguish from a string value of true/false and the Boolean, built-in, supported data type of true/false.  Some programming languages support Boolean or bit values.  Ruby has a number of data types.  There is a feature that Ruby supports to test for most of its datatypes.  By appending to a variable this ".is_a?", you can test if a variable is a string, numeric, etc.  However, there is no supported way we know of for using this ".is_a?" determining if a variable is a Boolean.  What do you do?

Solution
Just assign var1 to the variable you want to check, eliminate the first line below, and run this code snippet in your program:

var1 = system("date") # System commands always return true or false values.
# Assign var1 to the variable you want to determine if it is a Boolean or not.  
as = var1.is_a? String
if as
   puts "Ruby does not consider var1 to be a Boolean"
else
   ns = as ? "true" : "false"
   if ns
        puts "Ruby considers var1 to be a Boolean"
   else
        puts "Ruby does not consider var1 to be a Boolean"
   end
end