Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there some way to define user specific hosts - like in /etc/hosts? Maybe something like ~/.hosts?

I want to be able to specify alternative host names for computers in my local network that I frequently connect to. For example when logging in using ssh, copying stuff with rsync etc.

share|improve this question

migrated from Jul 15 '09 at 13:38

This question came from our site for professional and enthusiast programmers.

can you tell what you are actually wanting to do? – Anonymous Jul 15 '09 at 13:28
up vote 21 down vote accepted

For anything ssh based (including rsync over ssh) you can add entries to your ~/.ssh/config file


Host myhost

Then ssh myhost will connect you to

share|improve this answer
+1 very useful :-) – David Z Jul 15 '09 at 14:13
add a "User" option and It's a great recipe for heterogenous systems. – hayalci Jul 15 '09 at 14:16
I use this approach with wildcards and bash completion for hostnames with the HOSTFILE environment variable. I end up with tab-completion of the 'alternate' hostnames quite nicely. – ericslaw Jul 15 '09 at 14:29

Specific applications may have something you can use, like Nick suggested, but there is no user homedir equivelent of the /etc/hosts file.

When applications try to resolve hostnames it gets handled by NSS. You can check how NSS handles hostnames on your system by looking at /etc/nsswitch.conf

$ grep host /etc/nsswitch.conf 
hosts:          files dns

This means that hostnames will be resolved first against the file database (/etc/hosts), and failing that against the dns details specified in /etc/resolv.conf

share|improve this answer

I was wondering the same thing and a colleague found this solution:

It basically involves setting an environment variable (HOSTALIASES) which points to the file to use for host aliases (you could use ~/.hosts for example).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.