I'm looking for a DRY solution that would allow me both

ssh server-alias


ping server-alias

I know the former is reading .ssh/config, and the latter /etc/hosts, but I'd rather not repeat the same aliases in both files. Is it a good idea to have a single source for both? If so, how can I accomplish it?

I can simply omit HostName line from the .ssh/config entry, and it will be read from /etc/hosts, does this approach have any disadvantages? If so, what should I use instead? It's intended for a single-user laptop, and no host masking is required.

  • 4
    both files serve different purpose. you can build (update/patch) one or the other with sed/awk magic easilly, but remember that ~/.ssh/config can be in every users' home (including possible future users), an it can be actually used for "masking" real hosts. e.g. Host *.com, Hostname fake.example.edu... Jul 4, 2016 at 9:50
  • Thanks, it's intended for a single-user laptop, and no masking is required.
    – dimid
    Jul 4, 2016 at 9:55
  • 1
    Searching for "best practices" is usually "opinion based". If you use ssh_config for aliases only, the /etc/hosts will do the same job. So what is the actual problem?
    – Jakuje
    Jul 4, 2016 at 10:53
  • Edited the "best practice" part. I hope the question is more clear now.
    – dimid
    Jul 4, 2016 at 11:13

1 Answer 1


Yes. There is no need to clutter your .ssh/config with Hostnames if all you want is tab expansion.

Entries in /etc/hosts will be sufficient.

.ssh/config is for specifying login names etc.

Maybe you should use wildcards in your hostnames in .ssh/config if you really want to specify connection details there at all.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .