Coder of Salvation™   — programming / opensource / console / minimal

npm git cloning private bitbucket repository with ssh key on openshift

Simple approach on using alternate ssh-keys to use with private repositories on openshift

The problem

Solution step #1: generate an sshkey!

login to your openshift application ('foo' e.g.)

$ rhc ssh foo

go to the data dir and create an ssh-key like so:

$ pwd
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/openshift/54228f2a5973ca43cc000b8e/.ssh/id_rsa): /var/lib/openshift/3cc000b8e/app-root/data/id_rsa

Make sure you enter the right directory in the 'Enter file in which..'-prompt (hence the 'pwd' command)

Solution step #2: an ssh wrapper!

Now lets create an ssh wrapper:

$ echo -e '#!/bin/bash\nssh -t -o "StrictHostKeyChecking no" -i $OPENSHIFT_DATA_DIR/id_rsa "$@"' > sshwrapper
$ chmod 755 sshwrapper

Then run this (just to test, or in your deployscript):

GIT_SSH=$OPENSHIFT_DATA_DIR/sshwrapper npm install git+ssh://
GIT_SSH=$OPENSHIFT_DATA_DIR/sshwrapper npm update  git+ssh://

or simply:

$OPENSHIFT_DATA_DIR/sshwrapper git clone ssh://

Voila! This should work. If not, please revise the steps above, or comment below.

In retrospect

The 'StrictHostKeyChecking no' option was passed, to enable automatic deployments (or calls from .openshift/actionhooks/deploy hook).

comments powered by Disqus

All rights reserved by Leon van Kammen under this license