21

What would be a walkthrough on how to set up multiple SSH keys?

I'm trying to connect to my remote server and GitHub account. I've got SSH access established with GitHub, but when I used ssh-keygen -t rsa and hit Enter, the terminal prompted me if I wanted to override the one that already exists. How can I create a new SSH key just for the remote server?

1 Answers1

40

You should specify the output file, for example:

ssh-keygen -t rsa -f ~/.ssh/my-new-key

Then to connect:

ssh -i ~/.ssh/my-new-key 192.168.x.x

Or set up an SSH configuration file:

nano ~/.ssh/config

Then put in something like:

Host my-server
    HostName 192.168.x.x
    User root
    Port 22
    IdentityFile /home/username/.ssh/my-new-key

Finally:

ssh my-server
Ravexina
  • 55,668
  • 25
  • 164
  • 183
  • Swell ! All I had to do is create a separate folder for the new key so it wouldn't be in conflict with the other one. Very nice ! What I don't understand though is I intentionally set the ssh key to be password-free but when I type ssh my-server and hit Enter I get prompted for password. – Mark Alexa Jun 28 '17 at 13:48
  • 2
    I'm not sure, make sure that ssh-agent is running and use ssh-add to add your key to key lists so it doesn't ask you for password anymore. (At this session). – Ravexina Jun 28 '17 at 13:52
  • I just realised that it's not a new folder what I created. I just gave it a name. I didn't know you can name a ssh key. Good to know ! – Mark Alexa Jun 28 '17 at 13:53
  • Shouldn't I copy the unique ssh formula into server's ssh file of known keys ? I think it should work similar to GitHub at this regard. – Mark Alexa Jun 28 '17 at 13:55
  • You should add your new public key to your server, known hosts will be updated automatically... – Ravexina Jun 28 '17 at 13:56
  • Ahh that's what's missing here .... – Mark Alexa Jun 28 '17 at 13:57
  • Well I copied the public key into server's config file but didn't work. Still prompts me for password everytime I logging in. Never mind. This isn't end of the world. It's just annoying having to type in password since I'm accessing my server only from this laptop. I can live with it. I should be happy I have access to it at all. :) Cheers ! – Mark Alexa Jun 28 '17 at 14:31
  • ssh-add ~/.ssh/mynewkey it asks your password once then you don't have to enter it again (in this session). – Ravexina Jun 28 '17 at 14:36