tomas-sentkeresty
12/15/2016 - 6:26 PM

GIT-SETUP.md

Create default identity

Generate default identity file

  1. Go to ssh directory and generate identity file
cd ~/.ssh
ssh-keygen
  1. Press enter to use default file name /Users/<username>/.ssh/id_rsa.

  2. Set passphrase or leave empty.

  3. Check if indentity file was created:

ls -lsa ~/.ssh

Add identity to ssh-agent

  1. Check if the ssh-agent is running.
$ ps -e | grep [s]sh-agent 
 9060 ?? 0:00.28 /usr/bin/ssh-agent -l
  1. If the ssh-agent isn't running, start it manually:
$ ssh-agent /bin/bash
  1. Load your new identity into the ssh-agent management program using the ssh-add command.
$ ssh-add ~/.ssh/id_rsa 
Enter passphrase for /Users/emmap1/.ssh/id_rsa:
Identity added: /Users/emmap1/.ssh/id_rsa (/Users/emmpa1/.ssh/id_rsa)
  1. Use the ssh-add command to list the keys that the agent is managing.
$ ssh-add -l 
2048 7a:9c:b2:9c:8e:4e:f4:af:de:70:77:b9:52:fd:44:97 /Users/manthony/.ssh/id_rsa (RSA)
  1. Repeat process and create identity file named id_personal and id_<companyname> (E.g id_goodrequest)

Add created keys to Bitbucket account

  1. From Bitbucket Cloud, choose avatar > Bitbucket settings

  2. In terminal window, copy the contents of your id_personal.pub identity file that contain public key.

2.1 In Mac OSX, the following command copies the output to the clipboard:

$ pbcopy < ~/.ssh/id_personal.pub

2.2 Copy contents of indentity file in Linux:

$ cat ~/.ssh/id_personal.pub
  1. Paste the copied public key into the SSH Key field.

  2. REPEAT the same process with identity file named id_<companyname>.pub.

Add SSH config file

Host bitbucket.personal
  User git
  HostName bitbucket.org
  IdentityFile ~/.ssh/id_personal
  IdentitiesOnly yes

Host bitbucket.goodrequest
  User git
  HostName bitbucket.org
  IdentityFile ~/.ssh/id_goodrequest
  IdentitiesOnly yes

Host lisa
  User ubuntu
  HostName 52.29.214.27
  IdentityFile ~/.ssh/lisa.pem
  IdentitiesOnly yes

Clone repository

Repository ssh adress look like this: git@alias:<accountname>/<reponame>.git. When you want to use specific public key replace alias part of adress with bitbucket.personal or bitbucket.goodrequest.