I always found the instructions on how to install an SSH key confusing and long-winded. Here’s how I did it:
Generate the SSH Key
Open a Terminal and type:
% ssh-keygen
Press Enter a few times to get through the prompts.
It should save the two files you need in a hidden folder in your home directory. Try to list out the files:
% ls ~/.sshid_rsa id_rsa.pub
Add the Key to SSH-Agent
First, start the agent:
% eval `ssh-agent`Agent pid xxxx
Next, add the key to the agent:
% ssh-add -K ~/.ssh/id_rsa
Remember After Restart
You need to make sure that your config file is set up so that macOS remembers to use it.
% touch ~/.ssh/config
% open ~/.ssh/config
This should open the config file in a text edit. Make sure that the config file has the following lines:
Host *
UseKeychain yes
Add Public Key to BitBucket
First, we copy the key to the clipboard:
% pbcopy < ~/.ssh/id_rsa.pub
Then, go this URL and click Add Key: https://bitbucket.org/account/settings/ssh-keys/
Simply paste it into the big textbox and add a label (e.g. “MacBook Key”)
Verify Everything Works
In a Terminal window, type:
% ssh -T git@bitbucket.org | grep logged
logged in as <YOUR USERNAME>