User Tools

Site Tools


sysadmin:ssh_conf

This is an old revision of the document!


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]}"
sysadmin/ssh_conf.1763742409.txt.gz · Last modified: by mlivolsi