Make sure you have .ssh folder created:
$ mkdir ~/.ssh
$ chmod 700 ~/.ssh
create different ssh key according the article Mac Set-Up Git
$ ssh-keygen -t rsa -C "[email protected]" -f "key-name"
Please refer to github ssh issues for common problems.
for example, 2 keys created at:
~/.ssh/id_rsa_github
~/.ssh/id_rsa_bitbucket
then, add these two keys as following
Make sure that the ssh-agent is running:
eval `ssh-agent`
$ ssh-add ~/.ssh/id_rsa_github
$ ssh-add ~/.ssh/id_rsa_bitbucket
you can delete all cached keys before
$ ssh-add -D
finally, you can check your saved keys
$ ssh-add -l
$ cd ~/.ssh/
$ touch config
$ subl -a config
Then added
# GitHub account
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_github
# Bitbucket account
Host bitbucket.com
HostName bitbucket.com
User git
IdentityFile ~/.ssh/id_rsa_bitbucket
Setup the SSH in the service of your choice:
After that, check if everything is ok:
- GitHub:
ssh -T [email protected]
- Bitbuket:
ssh -T [email protected]
Globally
$ git config --global user.name "foo"
$ git config --global user.email "[email protected]"
By project
$ git config user.name "foo"
$ git config user.email "[email protected]"