Ssh – Get hostnames into ssh tab-completion (with minimal editing)

bashcommand-line-interfacessh

I know I could get a list of hostnames into bash tab-completion of ssh by adding them to /etc/hosts, but since they are on DHCP, it's kinda bad practice.

Does anyone know another DHCP-aware way, that doesn't force me to interfere with Ubuntu too much?

(Global solution preferred)

Best Answer

The simplest way is to simply disable the HashKnownHosts option globally or in your personal .ssh/config file. If you disable that, and also have the bash-completion package installed, then any host you connect to will be available for auto-completion after you have connected the first time.

You could use ssh-keyscan to build up a nice big list to pre-populate your known_hosts file.