Patrick Ward words, code, and music

SSH Cheatsheet

I’m always forgetting the commands needed to run ssh routines, so this is where I list them for easy reference.

Using SSH Agent to work with multiple ssh keys

I use multiple ssh keys for various projects and servers and sometimes need to make sure they are in the agent for quick access via ssh.

List currently loaded keys

ssh-add -l

Add a new key to the ssh agent list

ssh-add ~/.ssh/workid

Create a new SSH identity

ssh-keygen -f ~/.ssh/workid -C "workid"

SSH Config file

Host workid
HostName workserver.local
IdentityFile ~/.ssh/workid
Host personalid
HostName personalserver.local
IdentityFile ~/.ssh/personalid

Convert OpenSSL (SECSH) format to SSH-RSA (OpenSSH) format

This will read the public key in openssl format from and output it to OpenSSH format on stdout.

ssh-keygen -f -i

Merge Two Git Repos Into One

I needed to merge two distinct git repositories into a single parent repository as subdirectories the other day. I wanted to remove the separate repositories and add them as subdirectories within the parent repo, all while retaining the original repo history.

After a little trial and error, I found the following worked well for me.

Within the following code examples, I’m using widgets as the new, merged repository and widget1 as an older repository to be merged in.

First, create the new parent repo and send it up to Github or Bitbucket:

  mkdir widgets
  cd widgets
  git init
  git remote add origin git@servername:username/widget1.git
  git add .
  git commit -m "Initial commit for merged repo"
  git push -u origin master

Simple enough. Next, I created a clone of each repo I wanted to merge and ran filter-branch on them to ensure that each repo looked as if it had always been developed within it’s own directory.

  git clone widget1 widget1_copy
  cd widget1_copy

  # This moves all files into a new widget1 directory
  git filter-branch --prune-empty --tree-filter '
  if [[ ! -e widget1 ]]; then
    mkdir -p widget1
    git ls-tree --name-only $GIT_COMMIT \
    | xargs -I files mv files widget1

The above procedure was run for each repository I wanted to merge into the widgets repository.

Finally, I merged each of the filtered repos into the new parent repo.

  cd widgets
  git remote add -f widget1 ../widget1_copy
  git merge -s ours --no-commit widget1/master
  git read-tree --prefix=/ -u widget1/master
  git commit -m "Merged widget1"

  # Once last check to make sure we have everything
  git pull -s subtree widget1 master

  # Finally, remote the remote and push
  git remote remove widget1
  git push

Again, the above procedure was run for each sub-repo I was merging in to the new repository.

The final result is that I have a single repository with each of the older repositories as a subdirectory of the new repo, along with the previous repository history in tact.

Setting Up a Laravel Application on Webfaction

I was working on a simple Laravel 4 application for a client recently and decided to put it on the Webfaction hosting platform. The platform itself is quite nice, but in order to make the Laravel application work properly, I had to go through a series of steps:

Setting Up Composer

Installing composer took a few extra steps to avoid errors and fit within the directory structure of the Webfaction user account:

  cd ~
  ln -s `which php55` ~/bin/php
  export PATH=$HOME/bin:$PATH
  curl -sS | php53

Once composer was installed, I was able to cd into my webapp directory and run the composer update:

  cd ~/webapps/MyLaravelApp/
  php55 ~/composer.phar update

Setting Up the Web Application

Once composer was installed and the Laravel dependencies were added, I was able to continue deploying the application.

Webfaction uses web applications to drive individual webapps. At first, I thought I could just add the Laravel application. However, Laravel apps require the document root to be set to the public directory. So, using the regular Webfaction application for that won’t work. The recommended solution is to add a Symbolic Link application and add the absolute path of the public directory to the Extra Info section of the application setup.

  1. Within the control panel, go to “Domains/Websites –> Applications”
  2. Choose “Add a New Applciation”
  3. Enter the name of your application (e.g. MyLaravelApp_Public) - This is just a symbolic link to the public directory of the Laravel application I setup earlier.
  4. Choose “Symbolic link” for the “App Category”
  5. Choose the appropriate PHP version for the “App Type”
  6. Ener the absolute path of the Laravel public directory to the “Extra Info” text field. For example:


Next, add this symbolic link application as the root application:

  1. Within the control panel, go to “Domains/Websites –> Websites”
  2. Choose the website you’re working with
  3. Under “Contents” choose “Add an application –> Reuse and existing application”
  4. Choose the symbolic link application you created earlier.
  5. Finally, don’t for get to save the website

At this point, you should have a working Laravel application on the Webfaction hostng platform.

Installing R from Homebrew on Mac OS X

I’m taking the Computing for Data Analysis on Coursera and needed to install the R language files. I prefer to install programs like R via homebrew. But, I ran into a few errors along the way. After a few tries and reading through issue 587 on Github, I was able to successfully install R via the following steps:

  1. First, I installed XQuartz to use as the X11 window system.
  2. Up next, the homebrew command line instructions:
brew update
brew tap homebrew/science
brew install r --env=std

It was the --env=std option that enabled me to fully install the R framework.