User Tools

Site Tools


sysadmin:ssh_conf

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
sysadmin:ssh_conf [2025/11/21 16:21] – created mlivolsisysadmin:ssh_conf [2025/11/21 16:31] (current) mlivolsi
Line 1: Line 1:
 ==== SSH Access Script ==== ==== 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) 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
 +
 +<code>
 +
 +#!/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]}"
 +</code>
 +
 +My ssh config
 +
 +<code>
 +#---------------------------------------------------------------
 +#_ 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
 +</code>
  
 +Obviously, you need to setup open-ssh on your servers and copy the required keys
sysadmin/ssh_conf.1763742082.txt.gz · Last modified: by mlivolsi