SSH tricks

Check SSH configuration
sshd -t

Show active SSH connections
lsof -i -n | egrep '\<ssh\>'

Script to keep alive SSH connection with varying IP:

#!/bin/bash

if [ -z "$(ps ax | awk '{print $9}' | grep 2200:svarm:2200)" ]
then
ssh -N -f -R 2200:svarm:2200 -p 2222 mynetwork.net
fi

Establish SSH tunnel to DB on background, save its PID and kill it afterwards:

#!/bin/bash

ssh  -N -L 3333:db.myserver.com:3306 jump-host &
pid=$!
do something
kill -9 $pid

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: