-
Open a terminal.
-
Run:
ssh -v- If it shows a version (e.g., OpenSSH), SSH is installed. If not, install it with:
sudo apt update sudo apt install openssh-client
- If it shows a version (e.g., OpenSSH), SSH is installed. If not, install it with:
- In the terminal, generate a new SSH key:
ssh-keygen -t ed25519 -C "your_email@example.com"- Replace
"your_email@example.com"with your email. - If your system doesn’t support
ed25519, use:ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
- Replace
- Press Enter to accept the default file location (
~/.ssh/id_ed25519or~/.ssh/id_rsa). - Optionally, enter a passphrase for extra security (or leave blank).
- Start the SSH agent:
eval "$(ssh-agent -s)"
- Add your SSH private key to the agent:
ssh-add ~/.ssh/id_ed25519- Use
~/.ssh/id_rsaif you generated an RSA key instead.
- Use
- Display your public key:
cat ~/.ssh/id_ed25519.pub- Or
cat ~/.ssh/id_rsa.pubfor RSA.
- Or
- Copy the output (starts with
ssh-ed25519orssh-rsa).
- Log in to your Bitbucket account.
- Go to Personal settings > SSH keys.
- Click Add key.
- Paste your public key (from Step 4) and give it a label (e.g., "Ubuntu PC").
- Save it.
- In the terminal, test the connection to Bitbucket:
ssh -T git@bitbucket.org
- If successful, you’ll see a message like:
"authenticated via ssh key ... You can use git to connect to Bitbucket..."
- On Bitbucket, go to your repository and copy the SSH URL (e.g.,
git@bitbucket.org:username/repo.git). - In the terminal, clone it:
git clone git@bitbucket.org:username/repo.git
- Replace the URL with your repository’s SSH URL.
- If you get a "Permission denied" error:
- Ensure your public key is correctly added to Bitbucket.
- Check file permissions:
chmod 600 ~/.ssh/id_ed25519(orid_rsa).
- If asked about the host key, type
yesto accept it.
That’s it! You should now be connected to Bitbucket via SSH on Ubuntu. Let me know if you run into any issues!