Open a terminal or command prompt on your computer and run the following command to generate an SSH key pair:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Replace "[email protected]" with your actual email address associated with your Bitbucket account. You can also choose a different filename and location for your SSH key if desired.
-
Copy the contents of the public key file. On most systems, the public key file is located at
~/.ssh/id_rsa.pub
. If you are using docker container it is located at/root/.ssh/id_rsa.pub
, ( Generate the SSH key id_rsa.pub if the file does not exist, from here) -
In your Bitbucket account, go to "Settings" or "Account Settings" and look for the "SSH keys" or "SSH access keys" section.
-
Click on "Add key" or "Add SSH key" and paste the contents of your public key into the provided field. Give the key a descriptive label if you want.
-
Save the key.
Run the following command in the terminal or command prompt to test the SSH connection to Bitbucket:
ssh -T [email protected]
If the connection is successful, you should see a message like "logged in as your_username." or "You can use git to connect to Bitbucket. Shell access is disabled".
If you have existing Git repositories, you'll need to update the remote URLs to use SSH instead of HTTPS. To do this, navigate to the local repository directory in the terminal or command prompt and run the following command:
git remote set-url origin [email protected]:your_username/your_repository.git
Replace "your_username" with your Bitbucket username and "your_repository" with the name of your repository.
With SSH access set up, you can now clone, pull, push, and interact with your Bitbucket repositories using the SSH protocol.
Free Software, Hell Yeah!