1

I set up hostname aliases in .ssh/config, which works great:

Host my-web
  HostName 515.346.96.21 

So I can do this:

ssh my-web

But in a browser, I still need to type in "http://515.346.96.21". It would be great to be able to do "http://my-web".

Short of using a Dynamic DNS, or writing a script to synchronise changes with /etc/hosts, is there a way to use the aliases in SSH more widely? I create and destroy VMs with different IPs pretty often, so am constantly updating ~/.ssh/config.

Steve Bennett
  • 5,750
  • 12
  • 47
  • 59

3 Answers3

5

You can't re-use the HostName alias from ~/.ssh/config elsewhere. What you could do is update your /etc/hosts file with entries for your hosts e.g.

515.346.96.21 myweb
user9517
  • 115,471
  • 20
  • 215
  • 297
1

On further reflection, this seems like the way to go:

In /etc/hosts:

192.168.0.27    my-server

In ~/.ssh/config:

Host my-server
IdentityFile ~/foo.pem
User ubuntu

You still have to edit two files, but at least you're not duplicating any information. If the IP changes, you update /etc/hosts. If key or user change, your update .ssh/config. Plus, host name wildcards still work:

/etc/hosts:

company-server1: 192.168.0.44
company-server2: 192.168.0.45
company-server3: 192.168.0.46

~/.ssh/config:

Host company-*
IdentityFile ~/foo.pem
User ubuntu
Steve Bennett
  • 5,750
  • 12
  • 47
  • 59
0

You can just forget about setting aliases anywhere, if you use something like Avahi. This lets your workstation and servers (even virtual ones, if you bridged the virtual network) find each other and address each other by name.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972