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/shaun_rsa.pub.

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 shaun_rsa.pub

 

So now we got a private key file (shaun_rsa) and public key file (shaun_rsa.pub). 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/www.nerdifymylife.com/.ssh/authorized_keys

-rw——- 1 http://www.nerdifymylife.com root 793 Dec 18 19:32 /www/sites/www.nerdifymylife.com/.ssh/authorized_keys

root@shauntest:~# ls -lah /www/sites/magento.nerdifymylife.com/.ssh/authorized_keys

-rw-r–r– 1 root root 412 Dec 18 19:33 /www/sites/magento.nerdifymylife.com/.ssh/authorized_keys

root@shauntest:~#

 

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 http://www.nerdifymylife.com@www.nerdifymylife.com

http://www.nerdifymylife.com@shauntest:~$ exit

Shauns:Work shaun$ ssh -i /Users/shaun/.ssh/shaun_rsa magento.nerdifymylife.com@magento.nerdifymylife.com

magento.nerdifymylife.com@shauntest:~$ 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

Hostname http://www.nerdifymylife.com

Port 22

User http://www.nerdifymylife.com

IdentityFile ~/.ssh/shaun_rsa

Host nerdify-magento

Hostname magento.nerdifymylife.com

Port 22

User magento.nerdifymylife.com

IdentityFile ~/.ssh/shaun_rsa

 

Give it a try,

Shauns:Work shaun$ ssh nerdify-magento

magento.nerdifymylife.com@shauntest:~$ exit

Shauns:Work shaun$ ssh nerdify-www

http://www.nerdifymylife.com@shauntest:~$ 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

http://www.nerdifymylife.com@shauntest:~$ cd html

http://www.nerdifymylife.com@shauntest:~/html$ git init

Reinitialized existing Git repository in /www/sites/www.nerdifymylife.com/files/html/.git/

http://www.nerdifymylife.com@shauntest:~/html$ git add .

http://www.nerdifymylife.com@shauntest:~/html$ ls -lah .git/

total 280K

drwxr-xr-x   8 http://www.nerdifymylife.com vhosts 4.0K Dec 18 20:21 .

drwxr-xr-x   7 http://www.nerdifymylife.com vhosts 4.0K Dec 18 19:02 ..

drwxr-xr-x   2 http://www.nerdifymylife.com vhosts 4.0K Jun  3  2013 branches

-rw-r–r–   1 http://www.nerdifymylife.com vhosts   17 Jun  3  2013 COMMIT_EDITMSG

-rw-r–r–   1 http://www.nerdifymylife.com vhosts   92 Dec 18 20:20 config

-rw-r–r–   1 http://www.nerdifymylife.com 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.

http://www.nerdifymylife.com@shauntest:~/html$ 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://www.nerdifymylife.com@www.nerdifymylife.com/~/html/  shauntest.zerolag.com/www.nerdifymylife.com/files/html/

Cloning into ‘shauntest.zerolag.com/www.nerdifymylife.com/files/html’…

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:

WordPress.com Logo

You are commenting using your WordPress.com 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.