Dyce & Sons Ltd.

Helping IT since 1993

Octopress Deployment via RSync and 1&1

Thursday 22nd August, 2013

Sometimes, things are made out to be a whole lot harder than they really are.

Take copying files from your local machine to a remote server. RSync is your friend. I’ve known it’s theoretically possible, and indeed, I’ve used the rsync command locally for years. But actually getting it to talk to my 1&1 account - interacting with that beast never gives me the warm & fuzzies.

{% img [screenshot] /images/octopress_deploy.png ‘Deploying this blog to the 1&1 server, using rake deploy & rsync’ '' %}

Turns out, it’s pretty straight forward. Here’s the skinny:

Step 1 ~ Be Insecure

By which, I mean create a public key on your laptop that you’re never going to lose, right? Open up a copy of your terminal, and cd ~/.ssh/ followed by ssh-keygen -t dsa to create a public key. Hit return when it asks you for a filename, as the default is find. It will ask you for an passphrase (more than 4 characters!), and then to repeat the passphrase.

Richards-MacBook-Air:~ dd$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/Users/dd/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/dd/.ssh/id_dsa.
Your public key has been saved in /Users/dd/.ssh/id_dsa.pub.

Connect to your remote 1&1 server via an ftp app (I use Transmit, but I could have just as easily used Coda), and in the root directory, create a new directory .ssh. Copy the id_dsa.pub file across into this new folder, and rename it authorized_keys (yes, US spelling ;-) ).

Step 2 ~ Check Your Manual Login

Now, go back to your terminal and (making the correct substitutions for user name and domain name, type:

ssh -l myUserName mysite.address.com

Your Mac should now ask for the passphrase, and at the same time allow you to save it to your keychain. This is the key step.

You should now get a connection into the remote 1&1 server.

At the prompt, type cd ~ to take you to the home directory, then navigate to where you want to sync your files to, and then pwd to get the full path to the directory.

Step 3 ~ Let Octopress Know What’s What

You now have all the parts of the puzzle.

Nip back to your Octopress directory, and edit the Rakefile, completing the rsync section:

# -- Rsync Deploy config -- #
# Be sure your public key is listed in your server's ~/.ssh/authorized_keys file
ssh_user       = "myUserName@mysite.address.com"
ssh_port       = "22"
document_root  = "/directory/result/of/pwd/command/"
rsync_delete   = true # If you're feeling brave!!!
rsync_args     = ""  # Any extra arguments to pass to rsync
deploy_default = "rsync"

The document_root bit is important - this is what you were told when you used the pwd (present working directory) command on the remote server; it should be the folder that the static website is stored in, and you need the trailing slash.

Step 4 ~ Take It For A Spin

Now fire up your blog, edit some markdown files, and then

rake generate
rake deploy

And Robert is your mother’s sibling.