Setting up an SSH key can be a confusing and tedious process, but it doesn't have to be. This blog post will show you a simple and straightforward method for installing an SSH key on your Mac.
Step 1: Generate the SSH Key
To generate your SSH key, open a Terminal window and type:
~ ssh-keygen
Press enter a few times to go through the prompts. This will create two files in a hidden folder in your home directory, called "id_rsa
" & "id_rsa.pub
." You can verify that the files have been created by typing:
~ ls ~/.ssh
id_rsa id_rsa.pub
in the Terminal.
Step 2: Add the Key to SSH-Agent
To ensure that macOS remembers to use your SSH key after a restart, you will need to add it to the SSH-Agent. To do this, type:
~ eval ssh-agent
Agent pid xxxx
in the Terminal, then:
~ ssh-add -K ~/.ssh/id_rsa
to add the key to the agent.
Step 3: Remember After Restart
To make sure that your config file is set up correctly, type:
~ touch ~/.ssh/config
and
~ open ~/.ssh/config
in the Terminal. This will open the config file in a text editor. Ensure the config file includes the following lines:
Host *
UseKeychain yes
Step 4: Add Public Key to BitBucket
To add your public key to BitBucket, copy the key to the clipboard by typing:
~ pbcopy < ~/.ssh/id_rsa.pub
in the Terminal. Then, go to this URL: https://bitbucket.org/account/settings/ssh-keys/ and click "Add Key.
" Paste the key into the textbox and add a label (e.g. "MacBook Key").
Step 5: Verify Everything Works
To verify that your SSH key is working correctly, type:
~ ssh -T git@bitbucket.org | grep logged
in the Terminal. If everything is set up correctly, you should see the message "logged in as [YOUR USERNAME].
"
Following these simple steps, you can easily set up an SSH key on your Mac and start accessing your BitBucket repositories through the terminal. No more confusion or long-winded instructions!
Top comments (0)