Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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'm working on getting keys set up so I can easily log in to my servers. I know I can do things like: "ssh", but I have some servers that don't have a domain name. They have ip addresses (mainly database servers). Is there a way to type in something other than "user@" and instead type something like "user@myfavdatabase"? Basically a way to create an alias for ip addresses or something?

share|improve this question
A friend of mine once said, "If your servers don't have correctly forward and reverse DNS, they are broken." Is there some reason in this case that you can not request proper DNS? – kashani Feb 22 '11 at 18:50
up vote 0 down vote accepted

You can use an ssh config file in your home directory. For example:

[user@host ~]$ cat .ssh/config 
Host myfavdatabase
  User user

See man ssh_config for more information.

share|improve this answer
If you want your entire system to be able to use that alias, you can put it in your hosts file. Since you're on a Mac, if you go that route, make sure to flush out your Directory Service cache using "dscacheutil -flushcache" after updating /etc/hosts. – Marc Feb 22 '11 at 18:46
Don't use DNS aliases. Use /etc/ssh/ssh_config – Alex Holst Feb 22 '11 at 18:48
Let me clarify that. If you want things other than ssh to be able to use that alias, you'll want to add it to /etc/hosts. If you want all users on the system to be able to use that alias in ssh only, then @alex-holst is right about using /etc/ssh/ssh_config. Unless you're doing it on a Mac, in which case it's /etc/ssh_config. – Marc Feb 22 '11 at 19:06

Also, since you wrote about keyS in plural, adding the IdentityFile directive could be also useful in your ~/.ssh/config

Host myfavdatabase
  User user
  IdentityFile ~/.ssh/a_ssh_private_key_for_myfavdatabase

Also remember that you can create keys without password just by pressing enter when ssh-keygen prompts for a password.

If you go the more secure way of having a password, you can always add the password once to the ssh-agent using

ssh-add ~/.ssh/a_ssh_private_key_for_myfavdatabase

and typing your password only once. The ssh-agent will cache your password for future connections, at least until next logout or reboot.

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.