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 Answer 1

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
8
  • 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, 2017 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, 2017 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, 2017 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, 2017 at 13:55
  • You should add your new public key to your server, known hosts will be updated automatically...
    – Ravexina
    Jun 28, 2017 at 13:56

You must log in to answer this question.

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