George MacKerron: code blog

GIS, software development, and other snippets

iPhone + public key SSH authentication: lovely

I’ve been unhappy for a while having the SSH daemon on my web server VPSs with password authentication enabled. Of course, it’s on a non-standard port, blocks root logins, and takes a strong-ish password… but the risk of a successful dictionary attack has still felt too non-zero for comfort.

Equally, though, I’ve not wanted to give up the ability to log in to the servers from anywhere to fix things in an emergency, so I didn’t want to turn password authentication off and rely on public keys alone.

Until now, that is. I realised yesterday that, since I have iSSH on the iPhone, which does public key authentication, I can log into my servers from anywhere, even with password authentication turned off. Granted, doing anything serious on a tiny screen and slow connection is difficult. But all I actually need to be able to do from there is temporarily turn password authentication back on.

And to make this easy, I’ve put two ultra-simple scripts in ~/bin:

pwd_login_on.sh

#!/bin/bash
sudo sed -r -e 's/^PasswordAuthentication no$/PasswordAuthentication yes/' \
  -i.previous /etc/ssh/sshd_config
sudo /etc/init.d/ssh restart

pwd_login_off.sh

#!/bin/bash
sudo sed -r -e 's/^PasswordAuthentication yes$/PasswordAuthentication no/' \
  -i.previous /etc/ssh/sshd_config
sudo /etc/init.d/ssh restart

(These paths are suitable for Ubuntu 8.04).

Lovely.

Written by George

May 28th, 2009 at 2:03 pm

Posted in System admin

Free Adobe fonts

Quick tip: you can get hold of some of Adobe’s very nice professional fonts for free when you download the InDesign CS4 trial (and possibly other CS4 apps too).

These include:

  • Caslon Pro
  • Chaparral Pro
  • Garamond Pro
  • Minion Pro
  • Myriad Pro

If you don’t want to actually install InDesign, you can get to the fonts like so (if you’re a Mac user):

  • Mount (double-click) the downloaded disk image
  • Mount another disk image found on the newly mounted disk, at Adobe InDesign CS4/payloads/AdobeFontsAll/AdobeFontsAll.dmg
  • The fonts are inside /Assets/contents on this second disk

Note that these fonts may well be covered by a very restrictive licence: I haven’t checked.

Written by George

May 28th, 2009 at 1:17 pm

Posted in Mac,Web design

Testing in Internet Explorer for VMWare Fusion users

You might have noticed that Microsoft has lately started making available time-limited Virtual PC images of Windows installations with (separately) Internet Explorer versions 6, 7 and 8.

This is brilliant for Mac users who need to test websites in IE, because you get a real installation of each browser in its home environment, with the right JavaScript engine and working conditional comments, plug-ins, Windows Media Player, and so on. With the alternatives, such as running under Wine or using Multiple IEs in a single Windows virtual machine, one or more of these things tends to be missing.

More »

Written by George

May 28th, 2009 at 10:25 am

Posted in Mac,Web design

Paste unformatted keyboard shortcut in Office 2008 for Mac

iWork and some other Mac apps provide the keyboard shortcut Apple-Alt-Shift-V for the extremely useful command Edit > Paste and match style. But Office 2008 provides no such equivalent for its equivalent command, Edit > Paste > Unformatted Text > OK. Annoying.

Happily, you can fix this with a strategically named and placed AppleScript. Open /Applications/AppleScript/Script Editor, and paste in the following lines:

tell application "Microsoft Word" 
  paste special (text object of selection) data type paste text
end tell

Save in /Users/YourUserName/Documents/Microsoft User Data/Word Script Menu Items as Paste unformatted\mosV.scpt (the backslashed bit at the end of the filename provides the shortcut). Restart Word and you can now paste without importing extraneous styles with Apple-Alt-Shift-V.

Update

You might also try this alternative approach (via a handy comment elsewhere):

try
  set theClip to Unicode text of (the clipboard as record)
  tell application "Microsoft Word" to tell selection to type text text theClip
end try

This has the advantage of leaving the cursor where you expect, at the end of the pasted text — the original script fragment leaves it at the beginning. And no, type text text is sadly not a typo: that’s really how Word likes to be addressed.

Written by George

May 19th, 2009 at 4:35 pm

Posted in Mac

Getting a Firefox extension’s directory from within the extension

When creating a Firefox extension recently, I was surprised how much pain is involved simply in finding out, from within an extension, where that extension’s files are installed.

You have to create a ‘component’, which entails a fair chunk of unintelligible boilerplate code (well, unintelligible unless you’re much better acquainted with Firefox’s innards than developing a basic extension generally requires you to be).

Plenty of places will tell you roughly how to do it. But, after some experimentation, let me show you exactly how.

  • Copy this JavaScript file into your extension’s /components directory (if that directory doesn’t exist yet, create it).
  • Add these lines to your chrome.manifest:
component {723079F5-F880-40BB-8283-8266DEA93960} components/getExtDir.js
contract @mackerron.com/getExtDir;1 {723079F5-F880-40BB-8283-8266DEA93960}
  • Use it from elsewhere in your extension like so:
var own_path = Components.classes["@mackerron.com/getExtDir;1"]
  .createInstance().wrappedJSObject.getExtDir();

Update, August 2011 — Firefox 3 made this a bit less hairy, and Firefox 4 introduced a small but incompatible change. The updated code above works in Firefox 3 – 6, and most likely beyond. However, to make knowing your own directory useful (e.g. in order to locate and run an AppleScript there) you may have also to set <em:unpack>true</em:unpack> in install.rdf. This activates the old extension unpacking behaviour, which is deprecated because it increases load time.

Written by George

May 7th, 2009 at 1:23 pm

Posted in JavaScript

Importing the National Statistics Postcode Directory into PostGIS

This isn’t a very difficult task, but creating the table is somewhat laborious, so perhaps you’ll find the following SQL helpful.

More »

Written by George

May 5th, 2009 at 11:19 am

Posted in GIS,PostGIS,SQL