0

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 [email protected]", 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 "[email protected]" and instead type something like "user@myfavdatabase"? Basically a way to create an alias for ip addresses or something?

1
  • 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, 2011 at 18:50

2 Answers 2

0

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

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

See man ssh_config for more information.

3
  • 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, 2011 at 18:46
  • Don't use DNS aliases. Use /etc/ssh/ssh_config
    – Alex Holst
    Feb 22, 2011 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, 2011 at 19:06
0

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

Host myfavdatabase
  User user
  Hostname 1.2.3.4
  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.

You must log in to answer this question.

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