Bitbucket Pipelines : SSH connection to AWS EC2

I'm trying to connect in SSH to my AWS EC2 into my bitbucket pipelines.

I've generate and setup a KEY pair in AWS (Key pair name : 

From this, I add the public key and private key into my bitbucket SSH keys


I also add all my know host.

Then, when I try to connect in SSH using this :

"ssh will not be allocated because stdin is not a terminal.Permission denied (publickey)."

It's not working...

So I try to follow the guide to use multiple SSH keys (

a) I have put my base64 keys into my Environment variables as "MY_SSH_KEYS"

b) My public key is installed on AWS (/home/ubuntu/.ssh/authorized_keys)

c) I try to add manually a the root of my repository a my_known_hosts file with my pubic key and my host.


d) I change my pipelines to this :

      - step:
            - mkdir -p ~/.ssh
            - cat my_known_hosts >> ~/.ssh/known_hosts
            - (umask  077 ; echo $MY_SSH_KEY | base64 --decode > ~/.ssh/id_rsa)
            - ssh -i
            - sudo npm run dev

Still not working... I don't know what I can do !

Please, help me ! 

1 answer

What worked for me is to put the SSH Key from your screenshot into the /home/ubuntu/.ssh/authorized_keys file on a new line. The .ssh folder must be set up with drwx------ or the server will refuse it...that was a gotcha for me.

It looks like you already have your known_hosts set in Pipelines so that should be ok.

Then you should be able to just


Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

27,060 views 26 12
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you