I have a growing number of remote machines that ssh home and setup a connection to allow subsequent access via tunnel so I can get into them for maintenance.
Currently, I must manually configure these machines with a unique forward ssh port prior to install at the remote location by editing a script. The rest of the install is automated (PXE). It becomes tiresome (and risks error) setting this port manually, and prevents me confidently handing the full process off to a tech.
Question> Given a clean, debian install is it feasible to write a numeric hash function of (say) the mac address on eth0 that would be deterministic and fall in some range (say 30000-60000) and you could reasonably expect to be unique(++). I guess I've got bash, awk etc to play with. I would prefer to stick to shell related tools if possible but could use python if pushed.
(++) I would amend the tunnelling script to increment the port if it had problems on the first port tried.
Example Suggested Input: ifconfig eth0 | grep HWaddr | awk '{ print $5 }' == 08:00:27:aa:bb:cc
Example Required Output: 34567
This should also do what is required.
I really like your thinking and I'm curious to see your tunneling script but the cynic in me says someone will mention SSH keys :-)
We just use
cssh
for lots of small shell windows.Your hwaddr is just a big number, so you could always just take that mod whatever your range is and add the offset.
Here's the Math::BigInt version: