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?
2 Answers
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.
-
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.– MarcFeb 22, 2011 at 18:46
-
-
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.– MarcFeb 22, 2011 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
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.