How can I manage a list of frequently accessed hosts?
How can I quickly select and log in to the multiple hosts that I need to access via ssh? I'm building a shell script like the one below that uses dialog
to show a menu of hosts from the command line but I'm curious whether there's a better way.
#!/bin/dash
tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
trap "rm -f $tempfile" 0 1 2 5 15
while [ 1 ]
do
dialog --menu "Select Host" 0 0 0 \
"hostname1" "Host description 1" \
"hostname2" "Host description 2" \
"hostname3" "Host description 3" 2> $tempfile
HOSTNAME=`cat $tempfile`
if [ "x" = "x$HOSTNAME" ]; then
break
fi
ssh $HOSTNAME
done
Solution 1:
I like having each host set up with a short name in the ~/.ssh/config file on my client machine. Here's an example:
Host host1
HostName longhostname.mydomain.com
User remoteuser
IdentityFile ~/ssh-keys/id_rsa-my-keypair
This way I can just type "ssh host1" and immediately be logged in.
Solution 2:
For a GUI-based solution, look into SSHmenu.
Solution 3:
For the frequent logins I usually depend on short hostnames. Our company DNS contains most of them, the rest is in /etc/hosts. Combined with an ssh agent this is convenient enough for me. Oh yes, and: muscle memory. When I think of a hostname it magically appears on the screen if my fingers are close enough to the keyboard.
For the less frequent commands I usually depend on either the command history (if they're not that infrequent) or the Wiki where they are documented (copy/paste). This approach has the advantage that the less frequent tasks are more or less guaranteed to be documented completely.
I've thought about playing with automating command completion, so that ssh will automatically expand frequent hostnames on "tab", but up until today I've not missed this too much... One day I will...
Solution 4:
Honestly i can type ssh user@host
or when i'm on windows winkey+r then putty <server>
faster than any menuing system. That and I avoid using the mouse as much as possible because those ticks of the clock add up at the end of the day.
Solution 5:
I have a photographic memory so just remember their IP addresses, sad I know but of some benefit I have to say :)