User Tools

Site Tools


sysadmin:ssh_conf

SSH Access Script

Difficulty [1-10]: 1

If you have an SSH config file, and don't want to remember all the entries (in my case, with home and work, my list is about 50 entries)

Location: /opt/DBA/scripts/xmen

#!/bin/bash

looper=0
hosts=()

# Read only the lines we care about
grep -E 'Host|#_' ~/.ssh/config | \
grep -Ev 'HostName|StrictHostKeyChecking|UserKnownHostsFile|HostKeyAlgorithms' |
while read -r comment hostName _; do

    if [[ "${comment}" == "#_"* ]]; then
        echo "-----------------------------------------------------------"
    else
        ((looper++))
        hosts[$looper]="$hostName"
        echo "${looper}) $hostName"
    fi

done

echo -n "===> "
read -r answer

ssh "${hosts[$answer]}"

My ssh config

#---------------------------------------------------------------
#_ Mike Network
#---------------------------------------------------------------
Host n150-host
    HostName x.x.x.x
    User <your username>
    ForwardAgent yes                   # forward agent to target
    X11Forwarding yes                  # I need this for kvm gui
    ForwardX11Trusted yes

Obviously, you need to setup open-ssh on your servers and copy the required keys

sysadmin/ssh_conf.txt · Last modified: by mlivolsi