Trying to use SSH key as environment viariable

Hey everyone!


I'd like to use Pipelines environment variables to handle a SSH key. I literally followed the documentation. Well I think at least. But I keep getting "Permission denied (publickey).

Does anyone know where I could have a look to fix this?

Here's the configuration I use the same as the documentation) :

- mkdir -p ~/.ssh
- cat my_known_hosts >> ~/.ssh/known_hosts
- (umask  077 ; echo $SSH_KEY | base64 --decode > ~/.ssh/id_rsa)
- ssh $USER@$HOST 'echo "connected to `hostname` as $USER"'

1 answer

 A few things you can try:

1. Is your key base64 encoded? Heres a site that can do the trick: - also make sure that the encoded key has no spaces before saving into your environment variables. 

2. If you're not too worried about anyone reading your pipeline logs you can print out the contents of the id_rsa file to make sure you're getting a valid key:

- cat ~/.ssh/id_rsa

3. Add a '-v' flag to your ssh call and require the id_rsa file as well: 

- ssh -v -i ~/.ssh/id_rsa $USER@$HOST 'echo "connected to `hostname` as $USER"'

the -v flag will give you more verbose information about the connection process.

You might also have an issue using single quotes around the ssh command - using double quotes will render the environment variable before sending the command to your remote server (I learned that the hard way).

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

675 views 0 4
Read article

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot