SSH keys, backing up and Git

Well, WordPress 3.8 came out and its about damn time I join the modern age and setup some kind of code versioning and all that jazz. A fair amount of my clients use Capistrano, so I might take up learning some Ruby or maybe just enough to be dangerous.

Lets get down to the basics … ssh-keys. I’ve been using this site as a reference for years.

Shauns:.ssh shaun$ ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/shaun/.ssh/id_rsa): /Users/shaun/.ssh/shaun_rsa

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /Users/shaun/.ssh/shaun_rsa.

Your public key has been saved in /Users/shaun/.ssh/

The key fingerprint is:

07:30:59:9f:31:t2:a7:3c:39:7a:v3:17:36:41:7a:6d shaun@Shauns.local

The key’s randomart image is:

+–[ RSA 2048]—-+

|      +.o o      |

|     . + + +     |

|      . o + .    |

|     . + . + .   |

|      * S * o E  |

|     . + +.o .   |

|    . o . .      |

|     . . .       |

|                 |


Shauns:.ssh shaun$ ls -lah

total 48

drwx——   8 shaun  staff   272B Dec 18 19:31 .

drwxr-xr-x+ 19 shaun  staff   646B Dec 18 19:25 ..

-rw-r–r–   1 shaun  staff    61B Dec 17 16:54 config

-rw-r–r–   1 shaun  staff   415B Dec 17 16:03 known_hosts

-rw——-   1 shaun  staff   1.6K Dec 18 19:31 shaun_rsa

-rw-r–r–   1 shaun  staff   412B Dec 18 19:31


So now we got a private key file (shaun_rsa) and public key file ( Now we need to copy the public up to the server. I have root access on my VM (Yay for me!), so I just cut and paste. But lets set it up for both of my vhosts:

root@shauntest:~# ls -lah /www/sites/

-rw——- 1 root 793 Dec 18 19:32 /www/sites/

root@shauntest:~# ls -lah /www/sites/

-rw-r–r– 1 root root 412 Dec 18 19:33 /www/sites/



Add your IP to your firewall for the ssh port … you are using a local firewall and have moved ssh off port 22, right?

Give it a test:

Shauns:Work shaun$ ssh -i /Users/shaun/.ssh/shaun_rsa$ exit

Shauns:Work shaun$ ssh -i /Users/shaun/.ssh/shaun_rsa$ exit


So, that is pretty sweet but we have to type all of that out and that will get ignoring. This is where the .ssh/config file comes to the rescue. I’m going to setup some easier to use names to use …

Host nerdify-www


Port 22


IdentityFile ~/.ssh/shaun_rsa

Host nerdify-magento


Port 22


IdentityFile ~/.ssh/shaun_rsa


Give it a try,

Shauns:Work shaun$ ssh nerdify-magento$ exit

Shauns:Work shaun$ ssh nerdify-www$ exit

Now that is much better, nice and simple names to use.

Next, I want to todo two things:

  1. Create a Git repo of both vhosts
  2. Backup WP and upgrade

So lets turn our html dir into a Git repo$ cd html$ git init

Reinitialized existing Git repository in /www/sites/$ git add .$ ls -lah .git/

total 280K

drwxr-xr-x   8 vhosts 4.0K Dec 18 20:21 .

drwxr-xr-x   7 vhosts 4.0K Dec 18 19:02 ..

drwxr-xr-x   2 vhosts 4.0K Jun  3  2013 branches

-rw-r–r–   1 vhosts   17 Jun  3  2013 COMMIT_EDITMSG

-rw-r–r–   1 vhosts   92 Dec 18 20:20 config

-rw-r–r–   1 vhosts   73 Jun  3  2013 description

So, now we got some Git files (I didn’t list them all). Now, we need to commit the changes.$ git commit -m “Init Git commit 12/18/2013”

[master ffa3423] Init Git commit 12/18/2013

1059 files changed, 132596 insertions(+), 24433 deletions(-)

create mode 100644 Robots.txt

create mode 100644 gatling/index.html

Chopped the output.

So, there we go … we now have the files checked in to s Git repo … doesn’t do a lot of good just sitting up there like that.

Shauns:Work shaun$ git clone ssh://

Cloning into ‘’…

remote: Counting objects: 3112, done.

remote: Compressing objects: 100% (3050/3050), done.

remote: Total 3112 (delta 899), reused 0 (delta 0)

Receiving objects: 100% (3112/3112), 16.34 MiB | 1.75 MiB/s, done.

Resolving deltas: 100% (899/899), done.

Checking connectivity… done

Shauns:Work shaun$

And just like that … we cloned the Git repo and now to do the same for the other vhost.

Now that is done, it is time to run a backup of WP so we can upgrade. See you soon!


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.