I would like to be able to use ssh key to log into my web server via ssh and disable password authentication completely (to eliminate brute force from malicious ip addresses). So I am reading the documentation:


Now it instructs to do the following:

mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa

Here's the problem with running ssh-keygen. I already did that in order to generate keys to connect to my github account. So my .ssh directory already looks like this:

~/.ssh$ ls -l
total 16
-rw------- 1 viggy viggy 1766 Sep  5 20:36 id_rsa
-rw-r--r-- 1 viggy viggy  403 Sep  5 20:36 id_rsa.pub
-rw-r--r-- 1 viggy viggy 4422 Dec 22 11:45 known_hosts

Will running that command again overwrite the id_rsa files? Is there a better way to store both keys?

My ultimate goal here is to not overwrite my git keys, yet generate a ssh public and private key so that I can copy the public key to ~/.ssh/authorized_keys on my web server.

2 Answers 2


Pass the -f option to ssh-keygen to specify a different key file. I recommend names like ~/.ssh/target.id_rsa for the key that lets you log in to target, and use the default name ~/.ssh/id_rsa (if at all) for your default key.

To make sure that SSH will always try the right key when you connect (if it doesn't find the right key, it'll prompt you for a password, or will reject the attempt if passwords are disabled), add a IdentityFile directive to ~/.ssh/config, for example:

Host git
HostName git.example.org
User gitter
IdentityFile ~/.ssh/git.example.id_rsa

Host web
HostName mysite.hosting-provider.com
User webmaster
IdentityFile ~/.ssh/hosting-provider.id_rsa
  • I ran "touch config" in ~/.ssh since the config file isn't there by default Dec 22, 2013 at 18:15
  • @JohnMerlino Just edit it in your favorite editor, the file will be created the first time you save it. Dec 22, 2013 at 18:16
  • Just a side note, I think it is "User" rather than "UserName". Dec 22, 2013 at 19:02

The very first thing ssh-keygen will ask you is what to name the file. Just name it something else. Like...id_rsa2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.