EC2 Bitbucket SSH Setup

User
Amazon AWS EC2 Ubuntu Bitbucket SSH Clone of Repository

1- Generate a New SSH Key on EC2

ssh-keygen -t rsa -b 4096 -C "bitbucket-ec2" -f ~/.ssh/id_rsa

2- Add the Public Key to Bitbucket
Now, get the public key:

cat ~/.ssh/id_rsa.pub

a. Copy the output of the above command.

b. Go to Bitbucket → Personal Settings → SSH Keys.

c. Click Add Key, paste the key, and save.

3- Configure SSH on EC2

Edit your SSH config file:

nano ~/.ssh/config

Add the following:

Host bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa
StrictHostKeyChecking

4- Test SSH Connection to Bitbucket
ssh -T git@bitbucket.org
if successful you will see
logged in as your username

5- Now get ssh clone of bitbucket repo

Present above for linked in post in more attractive way

Assistant
# How to Set Up SSH Access for Bitbucket on an AWS EC2 Ubuntu Instance

If you're running an **AWS EC2 Ubuntu instance** and need to securely clone a **Bitbucket** repository via SSH, follow this step-by-step guide to configure SSH authentication seamlessly.

## **Step 1: Generate a New SSH Key on EC2**

Run the following command to create a new SSH key pair:

ssh-keygen -t rsa -b 4096 -C "bitbucket-ec2" -f ~/.ssh/id_rsa

– This generates a **4096-bit RSA key** for enhanced security.
– The `-C "bitbucket-ec2"` flag helps label the key for reference.

## **Step 2: Add the Public Key to Bitbucket**

Retrieve the public key:

cat ~/.ssh/id_rsa.pub

### **Next, add it to Bitbucket:**

1️⃣ **Copy** the output of the above command.
2️⃣ **Go to** *Bitbucket → Personal Settings → SSH Keys*.
3️⃣ **Click "Add Key"**, paste the copied key, and **save**.

## **Step 3: Configure SSH on EC2**

Edit your SSH configuration file:

nano ~/.ssh/config

Add the following:

Host bitbucket.org
    User git
    IdentityFile ~/.ssh/id_rsa
    StrictHostKeyChecking no

This ensures that SSH automatically uses your **private key** when connecting to **Bitbucket**.

## **Step 4: Test SSH Connection to Bitbucket**

Run:

ssh -T git@bitbucket.org

✅ If successful, you'll see a message confirming your authentication:

*"logged in as your_username"*

## **Step 5: Clone Your Bitbucket Repository via SSH**

Now, you can securely clone your repository:

git clone git@bitbucket.org:your_username/your_repository.git

Your repository is now **securely cloned** and ready for development! 🚀

💡 **Bonus Tip:** If you have multiple SSH keys, use the `-i` flag to specify a key while cloning:

GIT_SSH_COMMAND='ssh -i ~/.ssh/id_rsa' git clone git@bitbucket.org:your_username/your_repository.git

This method **enhances security** and ensures **seamless deployments** for your EC2-hosted projects.

#AWS #Bitbucket #EC2 #DevOps #Git #SSH

User
Make some short and Add icons
Assistant
# 🚀 **Clone Bitbucket Repo on AWS EC2 (Ubuntu) via SSH**

Set up secure SSH access to your **Bitbucket repository** on an **AWS EC2 Ubuntu instance** in just **5 easy steps!**

## 🔑 **Step 1: Generate SSH Key**

ssh-keygen -t rsa -b 4096 -C "bitbucket-ec2" -f ~/.ssh/id_rsa

✔️ Creates a **secure SSH key** for authentication.

## 🔗 **Step 2: Add SSH Key to Bitbucket**

📋 **Copy Public Key**

cat ~/.ssh/id_rsa.pub

🛠️ **Add it to Bitbucket:**
1️⃣ Go to **Bitbucket → Personal Settings → SSH Keys**
2️⃣ Click **"Add Key"**, **paste**, and **save**

## ⚙️ **Step 3: Configure SSH on EC2**

nano ~/.ssh/config

🔧 **Add the following:**

Host bitbucket.org  
    User git  
    IdentityFile ~/.ssh/id_rsa  
    StrictHostKeyChecking no

## ✅ **Step 4: Test SSH Connection**

ssh -T git@bitbucket.org

💡 **Success?** You'll see: **"logged in as your_username"**

## 🛠️ **Step 5: Clone Your Bitbucket Repo**

git clone git@bitbucket.org:your_username/your_repository.git

📂 **Your repo is now ready for development!** 🎯

💡 **Tip:** If using multiple SSH keys, specify the key while cloning:

GIT_SSH_COMMAND='ssh -i ~/.ssh/id_rsa' git clone git@bitbucket.org:your_username/your_repository.git

🚀 Now, enjoy a **secure & hassle-free Git workflow** on EC2!

#AWS #Bitbucket #EC2 #DevOps #Git #SSH #Cloud

Leave a Comment

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