OpenShift SSH Console

Connect and git clone from OpenShift without using the rhc tools

If for whatever reason you don’t want to install OpenShift’s rhc tools to your machine, you can still SSH into your applications, use FileZilla or git commit. It’s just a matter of configuring manually some stuff. I prefered this because I’m not a ruby user and it feels a burden to install it on my machine just for using the rhc tools.

You’ll need to download Putty to login through SSH and Puttygen so we can create our public and private SSH-RSA keys.

So let’s say you’ll create your application right now. I chose for this example a NodeJS cartridge( latest version).  After instantiating it, you’ll be presented with instructions on how to git clone the application so you can make changes to it.

OpenShiftApplicationCreated

Right on! Let’s try git cloning the app.

FatalErrorWhenGitCloning

Uh-Oh. Seems like something’s not right. The problem is that we haven’t set up the public and private SSH keys yet.

We’ll now cover how to create them, how to connect with putty, filezilla and then create a config file for git so it can successfully clone the repository.

Generating the SSH keys using Putty

Open PuttyGen and then click the Generate button. It will ask you to move the mouse so it can generate a random seed for the key. This takes a few seconds. At the end, it gives you the public key and a private key:

puttyKeyGen

It’s recommended to also set a password for the key. You’ll be asked for it each time you connect through SSH. The public key is what you need to add in the OpenShift console. As for the private key, you can save it wherever you want. I saved it in the .ssh folder located under C:\Users\[YourProfileName], since that’s where git manages the SSH keys.

Now you’ll have to copy the public key and go to OpenShift’s online console, go to the Settings tab and add this new key.

It should look something like this:

openshiftKeySaved

Connect via SSH to your OpenShift gear

In your application’s page you should have a string used for logging in remotely.

RemoteLoginString

Copy that, fire up Putty and paste it in the Host Name input box.

PuttyHostNameInputBox

Now go to Connection>SSH>Auth, hit Browse and search for your private SSH key you saved earlier (it should pe a .ppk file). When opening the connection, you might be asked if you want to trust the foreign machine, since its key fingerprint hasn’t been stored locally yet. If everything’s good, you should now be able to access your gear’s console, after entering the password you set earlier for the private key:

OpenShift SSH Console

Accessing the files with FileZilla

There’s already a tutorial that covers it better than I could on the OpenShift blog. The gist of it is this:

Fire up Filezilla. Go to Edit>Settings>Connection>SFTP and add the private key file you generated earlier:

filezillaPrivateKeyFile

Then click the Site Manager button(the first button on the left), hit the New Site button and enter your application’s URL in the Host text input, select the SFTP-SSH protocol, choose Ask for a password for the Logon Type and for the User enter your OpenShift UUID( that string that keeps appearing in the SSH commands).

fileZilleSiteManagerConnectionSettings

When you’ll connect, you’re going to be asked for that private key password again.

Git cloning and commiting

I suppose you have Git for Windows installed. We’re going to create a file named “config”( just like that, without any file extension) in C:\Users\[yourProfileName]\.ssh . That’s the file git uses to manage secure connections to repositories. Here’s the structure of the file:

Host [yourApplicationName]-[yourDomainName].rhcloud.com
    HostName latestnode-tal0s.rhcloud.com
    User git
    IdentityFile C:\Users\[userProfileName]\.ssh\sshKeyForGit

Woa, wait, wasn’t it supposed to be a .ppk file? Well, that works well with Putty on Windows, but it might not work for git. In my case it kept asking for the passphrase, even if it was correct. The solution is to generate another key with Putty, but this time to save the private key go to Conversions>Export OpenSSH key and save it without any file extension. Add the public key as usual in the OpenShift console’s settings.

Let’s test this:

gitCloneWorked!

It worked! And look, pushing code changes works too:

pushing-to-Git

Yay! Awesome!
Well, I hope this helped you ^_^. My motivation to make this article was that I might need some fast reference in the future, but it might help others. If you see this and have any tips and tricks related to git, feel free to leave a comment! 😀

Leave a Reply