After reading the above and glueing everything together, I've created the following Perl script (save it as mssh in /usr/bin and make it executable):
#!/usr/bin/perl
$iport = 13021;
$first = 1;
foreach (@ARGV) {
if (/^-/) {
$args .= " $_";
}
elsif (/^((.+)@)?([^:]+):?(\d+)?$/) {
$user = $1;
$host = $3;
$port = $4 || 22;
if ($first) {
$cmd = "ssh ${user}${host} -p $port -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no";
$args = '';
$first = 0;
}
else {
$cmd .= " -L $iport:$host:$port";
push @cmds, "$cmd -f sleep 10 $args";
$cmd = "ssh ${user}localhost -p $iport -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no";
$args = '';
$iport ++;
}
}
}
push @cmds, "$cmd $args";
foreach (@cmds) {
print "$_\n";
system($_);
}
Usage:
To access HOSTC via HOSTA and HOSTB (same user):
mssh HOSTA HOSTB HOSTC
To access HOSTC via HOSTA and HOSTB and use non-default SSH-portnumbers and different users:
mssh user1@HOSTA:1234 user2@HOSTB:1222 user3@HOSTC:78231
To access HOSTC via HOSTA and HOSTB and use X-forwarding:
mssh HOSTA HOSTB HOSTC -X
To access port 8080 on HOSTC via HOSTA and HOSTB:
mssh HOSTA HOSTB -L8080:HOSTC:8080
host2denies forwarding – Mala May 3 '12 at 6:48