Warning: Undefined array key -1 in /home/public/blog/class.comments.php on line 23

Warning: Attempt to read property "i" on null in /home/public/blog/class.comments.php on line 23

How To: Manage your dang website via git (specialized for NearlyFreeSpeech)

Last updated:

This is a reminder post for myself, because I just had to re-clone my website on my local machine and futzed about for half an hour before figuring it out. This advice should generally apply for any other host, if you're running into this post from Google or something, you'll just have to change the exact folders used.

Setting up a new website

Go into /home/private. Make a new folder, like domainname.git. cd into there. Run git init --bare.

Almost there! Head into hooks. Create a post-receive file containing:

GIT_WORK_TREE=/home/public git checkout -f

Mark it executable with chown +x post-receive.


Cloning it into a personal computer

Okay, so you remember your ssh login details: the @ address and the password. For NFSN, this is {username}_{sitename}@ssh.phx.nearlyfreespeech.net.

Now just:

git clone <ssh-address>:/home/private/domainname.git website

It'll ask for a password, then ta-da!

(But see below for a different clone command for password-less access.)

Setting up SSH keys

Passwords are annoying.

Find your SSH keys, they're probably named sshkey and sshkey.pub or something.

SFTP into your website server. (Identical to the ssh command.)

Head to /home/private, make a .ssh folder. cd into it. Upload your public and private keys.

Since this is NFSN, the next step is to tell the admin interface about your keys. I won't go into the steps there, they have a guide.

Now back on your local computer, set up an sshagent script:

eval `ssh-agent -s`
ssh-add ~/.ssh/sshkey
ssh-agent -k

(Modify path to the private key if necessary.)

Pop in it ~/bin or wherever, mark it executable, and run it.

Also set up an .ssh/config file (create it if it doesn't exist), adding:

Host nfsn
	Hostname ssh.phx.nearlyfreespeech.net
	User {username}_{sitename} (fill these in!)
	IdentityFile ~/.ssh/sshkey

And now, instead of cloning with the explicit address as described above, clone with:

git clone nfsn:/home/private/domainname.git website

Now when you use git, it'll use your keys rather than asking for a password!

(a limited set of Markdown is supported)