Use SSH Key Exchange with BitBucket instead of HTTPS

By default, my BitBucket Git repository uses the HTTPS URL instead of the SSH. As a result, I get prompted for my password every time I push code to my BitBucket Git repository.

$ git push
Password for 'https://<repo_owner>':

You should see your BitBucket account username in place of <repo_owner> . If you want to avoid having to do this every time, you must configure BitBucket to have your SSH Key. Therefore, copy your SSH key (or generate one if you haven’t already) and add it your account settings in BitBucket (ie,<repo_owner>/ssh-keys/).

$ cat ~/.ssh/ | pbcopy

Now, you must configure your Git to use SSH instead of HTTPS. You can do this globally for all Git repos on your machine/account, by doing the following:

$ git config --global url.ssh://<repo_owner> https://<repo_owner>

You can confirm that this works by checking your global configuration file and look for the insteadOf:

$ cat ~/.gitconfig
[url "ssh://<repo_owner>"]
	insteadOf = https://<repo_owner>

Now, you’ll be able to push code changes to BitBucket without being prompted for a password.


Leave a Reply

Your email address will not be published. Required fields are marked *