Git Bitbucket Add SSH
Copy the SSH Public Key
In the previous chapter, we created an SSH key pair.
Now we will use the clip <
command to copy the public key to our clipboard:
Example
clip < /Users/user/.ssh/id_rsa.pub
Go to Bitbucket, navigate to the lower left corner, click your profile, and select: Personal Settings:
Then select "SSH keys". and click the "Add key" button:
Select a title, and paste the public SSH key into the "Key" field, and click "Add Key":
You will be prompted to supply your SSH passphrase.
You will see your new SSH key added:
Test SSH Connection to Bitbucket
Now we can test our connection via SSH to Bitbucket:
Example
ssh -T git@bitbucket.org
The authenticity of host 'bitbucket.org (104.192.141.1)' can't be established.
RSA key fingerprint is SHA256:*************************************.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'bitbucket.org,104.192.141.1' (RSA) to the list of known hosts.
Enter passphrase for key '/Users/user/.ssh/id_rsa':
logged in as w3schools-test
You can use git to connect to Bitbucket. Shell access is disabled
If the second last line contains your username on Bitbucket, you are successfully authenticated!
Add New Bitbucket SSH Remote
Now we can add a new remote via SSH to our Git.
First, get the SSH address from our repository on Bitbucket:
Then use that address to add a new origin:
Example
git remote add ssh-origin git@bitbucket.org:w3schools-test/hello-world.git
Note: You can change a remote origin from HTTPS to SSH with the command: git remote set-url remote-name git@bitbucket.org:username/repository.git
Example
git remote set-url origin git@bitbucket.org:w3schools-test/hello-world.git