Sunday, May 15, 2016

Two And More SSH Keys in OSX

Short note about maintaining several "public - private" ssh key pairs in OSX.

Let's assume that You already have one "public - private" key pair locally which You're using for accessing something (git, jenkins etc.) and You don't want to use same keys for another resource then just follow next steps.

1. Move to Your .ssh directory

 $ cd ~/.ssh  

2. Generate key pair with next command

 $ ssh-keygen -t rsa -f ~/.ssh/secondKey -C "email@email.com"  

if You won't add secondKey (or whatever You want it to be named) this command will override Your main key, also You can add a key phrase or leave it blank.

3. Add an entry to Your config file inside .ssh folder (if You don't have that just create one with - $ touch config)

 Host firsthost.com  
  User git  
  Hostname firsthost.com  
  PreferredAuthentications publickey  
  IdentityFile ~/.ssh/id_rsa  
 Host secondhost.com  
  User git  
  Hostname secondhost.com  
  PreferredAuthentications publickey  
  IdentitiesOnly yes  
  IdentityFile ~/.ssh/secondKey  

That's simply it and if You need more keys - just repeat those steps above.

No comments:

Post a Comment