Super User is a question and answer site for computer enthusiasts and power users. 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

I keep having to type out ssh a lot. Instead of an alias, I just want to shorten that host name. I tried editing my hosts file to include shorthost at the bottom, but it's not resolving when I try to connect as ssh myusername@shorthost. Can anyone tell me why?

share|improve this question
up vote 9 down vote accepted

Use the ssh config file instead. The file path is ~/.ssh/config.

Example config:

Host shorthost
  User myusername

Then you can just run ssh shorthost.

share|improve this answer

Please accept @ggustafsson's solution. But since you asked why /etc/hosts didn't work, and he didn't cover that, I thought I'd cover it:

/etc/hosts is for mapping one or more hostnames to an IP address. It's not for mapping one name to another. Because it's not designed to do what you're looking for, it doesn't provide syntax for doing what you want. The syntax you made up is meaningless/invalid to the process that reads /etc/hosts, which expects each line to start with a numeric IP address.

share|improve this answer
Darn, I'd upvote you, but I need more reputation :( – user1541477 Jul 20 '12 at 20:08

If your only concern is ssh, you should accept ggustafsson's answer. However, if you need that for other IP tasks as well (e.g. ftp, ping, ...), and the host in question has a fixed ip (say, to have an example), you could add a line to your /etc/hosts like this: shorthost

(optionally, you could also add your somereallylonghost at the end of that, so that would also be resolved regardless of some DNS server being available). But keep in mind you'd have to update that line whenever the IP of your verylonghostnametoreplaceinthiscase changes -- which is not the case with the ssh config approach.

share|improve this answer

You must log in to answer this question.

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