SSH Bouncing Config Generator

SSH Bouncing Config Generator

From Consultancy.EdVoncken.NET

Jump to: navigation, search

Back to Secure Shell...

Maintaining the ~/.ssh/config entries by hand is tedious and error-prone. Therefore I've written a small generator + configuration to help you.

Generator script

 #!/usr/bin/perl
 #
 # Purpose:
 #  Generate ~/.ssh/config entries for hosts in DCS Andover
 #
 # File $Id:$
 
 # Bounce (Bastion) host
 my $BOUNCE="192.168.1.1";
 
 open( ENTRIES, "</home/ed/etc/gensshconfig.conf") or die "Cannot open config file.";
 my @entries=<ENTRIES>;
 close(ENTRIES);
 
 
 print "##########\n";
 print "# Remote #\n";
 print "##########\n";
 print "\n";
 
 chomp(@entries);
 foreach my $entry (@entries)
 {
   my ($ip,$host) = split("\t",$entry);
   print "# Host $host, destination address $ip\n";
   print "Host $host\n";
   print "  Hostname $host\n";
   print "  ProxyCommand \$HOME/bin/netcat-proxy-command $BOUNCE $ip\n";
   print "  LocalForward 1311 localhost:1311\n";
   print "  KeepAlive yes\n";
   print "\n";
 }
 
 print "\n";
 print "# EOF\n";
 
 # EOF

Note: Remember to replace the location of the configuration file with your own homedirectory...

Configuration file

The configuration file is a TAB-delimited file in the form <IP>\t<HOST>

 [ed@laptop ed]$ cat /home/ed/etc/gensshconfig.conf
 127.0.0.1       bastion
 192.168.15.101  dbs101
 192.168.15.102  dbs102