Is there some way to define user specific hosts - like in /etc/hosts? Maybe something like ~/.hosts?
5 Answers
For anything ssh based (including rsync over ssh) you can add entries to your ~/.ssh/config file
e.g.
Host myhost
Hostname myhost.example.com
Then ssh myhost will connect you to myhost.example.com
-
add a "User" option and It's a great recipe for heterogenous systems.– hayalciJul 15, 2009 at 14:16
-
1I 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.– ericslawJul 15, 2009 at 14:29
-
You can also use this to do cool stuff with Git, if you have multiple keys or accounts you need to use. You can set up path-based conditional config in Git, and use SSH settings to specify users/keys as needed. stackoverflow.com/questions/8801729/…– shearn89Jan 22 at 9:02
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
I was wondering the same thing and a colleague found this solution: http://blog.tremily.us/posts/HOSTALIASES/
It basically involves setting an environment variable (HOSTALIASES) which points to the file to use for host aliases (you could use ~/.hosts for example).
-
1
-
Another solution could be different "chroot" environments for different users. Even different root jails for same user, depending on certain criteria.
I found https://github.com/bAndie91/libnss_homehosts referenced in https://bbs.archlinux.org/viewtopic.php?id=266445
That we you could have ~/.hosts file, with same syntax as /etc/hosts has.