If you get an error message from git telling you: something like public key refused
Steps to make sure you have SSH and your Git remotes properly set up:
Client - Check which SSH key is being used by your SSH agent
make sure the agent is running
eval `ssh-agent`
make sure you are using the identity you think you are using
# list all identities used by agent
ssh-add -l
# no identities
if there are no identities, first make sure that you have generated proper keys
ls -la ~/.ssh
# empty ?
create some if your ~/.ssh
directory has no keys yet.
ssh-keygen
# Generating public/private rsa key pair.
# Enter file in which to save the key (/Users/g/.ssh/id_rsa): /Users/g/.ssh/id_rsa-bitbucket
# Enter passphrase (empty for no passphrase):
# Enter same passphrase again:
# Your identification has been saved in /Users/g/.ssh/id_rsa-bitbucket
# Your public key has been saved in /Users/g/.ssh/id_rsa-bitbucket.pub
# The key fingerprint is:
# SHA256:k2jJOxYX5VVXCPWh7F25jI4kXdQ+jSI6JWryap5X/AA g@unix
# The key's randomart image is:
# +---[RSA 3072]----+
# | . o=+o+|
# | o .o o+o|
# | . . +.o+|
# | .Eo.o+ + =o+|
# | *+S= + + +.|
# | ..o+*.o o |
# | ++. + . . |
# | .oo. . |
# | o+o |
# +----[SHA256]-----+
make sure that it was successfully created by looking for ~/.ssh/id_rsa-bitbuckt
and ~/.ssh/id_rsa-bitbuckt.pub
ls -la ~/.ssh
# drwx------ 10 g staff 320 21 Aug 11:39 .
# drwxr-xr-x+ 80 g staff 2560 11 Oct 20:42 ..
# -rw------- 1 g staff 2590 21 Aug 11:39 id_rsa-bitbucket
# -rw-r--r-- 1 g staff 560 21 Aug 11:39 id_rsa-bitbucket.pub
Now that we are sure we have some key pairs, let's add them to the ssh agent (so he uses them)
ssh-add ~/.ssh/id_rsa-bitbucket
From now on, if we attempt to push to a repository in Github or Bitbucket, we will be sure we are using the proper key.
If for some reason it starts complaining again, dont hesitate to:
eval `ssh-agent`
ssh-add -l
ssh-add ~/.ssh/id_rsa-bitbucket
Remote - Add your key to your account or repo
In bitbucket you can go to the repository and add keys (probably only for read). There are also account level keys, but don't always work.
For github it seems the keys are at the account level.
Make sure to add the public key ~/.ssh/id_rsa-bitbucket.pub
more ~/.ssh/id_rsa-bitbucket.pub
Copy the whole thing and paste it in your github or bitbucket.
Name it after some client identifier and date added.