Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I keep having to type out ssh myusername@somereallylonghost.numb3r5.ojd202nk.net a lot. Instead of an alias, I just want to shorten that host name. I tried editing my hosts file to include shorthost somereallylonghost.numb3r5.ojd202nk.net 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
add comment

3 Answers

up vote 9 down vote accepted

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

Example config:

Host shorthost
  User myusername
  HostName somereallylonghost.numb3r5.ojd202nk.net

Then you can just run ssh shorthost.

share|improve this answer
add comment

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
add comment

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, 123.123.123.123 to have an example), you could add a line to your /etc/hosts like this:

123.123.123.123 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
add comment

Your Answer

 
discard

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.