ssh – host hopping (with Jump host)

Most of the times I need to jump hosts with ssh. What do I mean by that. Let me try to explain :

Host Hopping

If I need to got to host h3 then I need to first login to h1 and from there to host h2 and finally to host h3. This can be done with .ssh/config file but for that I need to have some program like nc installed on all the hosts in between which might not be practical in all cases. So, here is something that I found very useful.

ssh -tt h1 ssh -tt h2 ssh -tt h3

In the above command, we can add usernames, if needed. And now for the best part, if we add entry for h2 in h1 and h3 in h2 in the .ssh/config file, then we don’t need to add usernames. Similarly setup passwordless ssh from h2 to h3 and h1 to h2 and you don’t need password for any of the hosts, how cool is that 🙂

Battery life on laptops

To improve your laptop battery life, just do the following:

sudo dnf install tlp tlp-rdw
systemctl start tlp
systemctl enable tlp

search for a port number

I find myself doing google everytime I want to search for port number mapping. So, here is a short script to do just that 🙂

#!/bin/bash -
#===============================================================================
#
# FILE: portfind.sh
#
# USAGE: ./portfind.sh
#
# DESCRIPTION:
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Amit Agarwal (aka),
# ORGANIZATION:
# CREATED: 08/29/2017 19:00
# Last modified: Tue Aug 29, 2017 07:00PM
# REVISION: ---
#===============================================================================
set -o nounset # Treat unset variables as an error
#This is the directory where you have mappings file downloaded
ODIR=/root
ofile=$ODIR/service-names-port-numbers.xml

if [[ ! -f "$ofile" ]]
then
wget http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml -O "$ofile"
fi
which xmlstarlet >/dev/null 2>&1
if [[ $? == 0 ]]
then
echo "xmlstarlet is installed"
else
apt-get install xmlstarlet
fi

#### xmlstarlet el -u service-names-port-numbers.xml
## registry/record - protocol and number
proto=${2:-tcp}
port=${1:-21}
(echo '';sed '1,4d' $ofile) |xmlstarlet sel -t -m "//record[protocol='$proto'][number=$port]" -o "Number(Protocol): " -v number -o '(' -v protocol -o ')' -n -o "Description :" -v description -n