Using Macfusion for SFTP Connections on OSX

Many of my colleagues use ExpanDrive for connecting to servers over SFTP, since OSX does not have a native client for doing so. ExpanDrive is nice because it integrates with the Finder and mounts a drive, instead of needing to interact with the filesystem using an application, such as FileZilla. However, ExpanDrive is not free, so I don’t use it. Normally, I spend my time developing in an Ubuntu 12.04 LTS virtual machine on VirtualBox, because Nautilus natively supports connections over SFTP.

ExpanDrive recently released an update that didn’t do a great job of announcing that it would be updating the software from version 2 to version 3, which invalidates your current license, and requires you to purchase a v3 license. Therefore, one of my coworkers upgraded to v3 unintentionally and was then locked out of using ExpanDrive until he bought a new license. This experience prompted me to revisit Macfusion as a method of connecting over SFTP from OSX.

Macfusion was built on MacFUSE, which is no longer actively maintained, and does not work with current versions of OSX. However, there is a successor to MacFUSE called OSXFUSE, and Macfusion can be configured to use the SSHFS filesystem plugin for OSXFUSE. Here’s how to get it set up:

  1. Install OSXFUSE
  2. Install SSHFS
  3. Install MacFusion
  4. Configure MacFusion to use OSXFUSE – open Terminal and run:

Now, you can open Macfusion and connect to SFTP shares. There are plenty of other filesystem plugins available – you would just need an OSXFUSE compatible client to leverage them.

Stop It with the Tiny Font

A modern design trend that drives me absolutely batty is this obsession with tiny text on websites – particularly blog and news sites, where the content is (presumably) intended to be read.

I consider myself mildly visually disabled – I use glasses to correct my nearsightedness, which is not severe. I can read what is on my computer screen equally well with or without glasses. However, I’m using a computer with a 15″ screen and a screen resolution of 1680×1050, which means the following:

  • 1680 / 1050 = 1.6 = aspect ratio of 16:10
  • Using Pythagoras’ theorem, I can calculate that one pixel on my screen is 0.225 mm
  • That means that the 11px font you are using is literally only 2.475 mm high on my screen, which is typically two feet away from my face
  • By comparison, most books are set with an 11pt (that’s point, not pixel) font, which is about 3.9 mm high, and most people read books about 6-12 inches away from their face
  • Since perceived size decreases by about half at double the distance, the 11px font on my screen appears to be about 1.24 mm at 24 inches vs. the 3.9 mm book at 12 inches
  • Conclusion: 11px font on my screen is approximately 3x smaller than the font size of a book held 12 inches from my face

As a consequence, I find myself constantly using my browser’s built-in zoom functionality (ctrl +) to zoom in items that I am reading so that they very nearly fill the screen. I find that a comfortable reading font size is somewhere around 24px on this screen (although on larger monitors, I can get away with less). On one of my 24″ external monitors, which is what I use for writing code all day, I set my font size in my text editor to 20px.

So why the obsession with small font size? Maybe it has something to do with page density and advertising space. Maybe it’s “trendy” and “cool.” As a user, and not a severely visually disabled user, I find it to be incredibly frustrating.

I suspect that part of the difficulty comes from increasing pixel density in devices and a corresponding lack of adjustment in design. The laptop I used a decade ago had a screen not much smaller than this, and its maximum resolution was 800x600px, which would yield a perceived pixel size of roughly twice what my current monitor displays, because design tracks pixels, and pixels aren’t fixed.

Command Chaining in Terminal

There are times when it is useful to execute multiple commands in sequence on the command-line with one press of the Enter key. This can be accomplished by separating commands with && or a semicolon.

Let’s take an example – synchronizing your local git branches with a remote. Say you want to pull changes from all of your remote branches with deltas, and then push your changes up to origin. If you have set up your local branches to track remote branches (most easily accomplished with git push -u origin <branchname>) you can run a bare git pull to see the branches that have changed. Once you get the list of changes, you can synchronize your changes with remote thus, assuming changes to remote master and a local feature branch called fb-reskin:

If the process of checking out, pulling changes, and pushing is time consuming, such as on a large repo, you can run this command and go make a sandwich and all of the sync operations will be done on your return – instead of waiting for each command to finish and then executing the next.

Another example is shutting down and disconnecting from a virtual machine. Often, after issuing the shutdown command, the SSH session remains open for a few seconds until the SSH daemon is killed and the connection terminates. You can chain the shutdown and exit commands together to issue the shutdown order and disconnect from the server in one go:

It is also handy for running updates:

Putting Postfix in Development Jail

When developing, it’s handy to be able to receive and read emails that are fired by your site, but without the risk of accidentally sending a bunch of spam to actual users. I came up with a method for keeping sendmail in “jail,” whereby all of the mail sent by sendmail would get remapped to a distribution list of my choosing, therefore allowing me to see what the system was sending without the system actually emailing anyone else.

I recently switched to Postfix (see my previous post) and I found a way to achieve the same functionality.

1. Create a Canonical Map

Create a canonical map file in POSIX regular expression format to store your rewrite rule(s):

Populate the file with this line, to rewrite all outgoing, non-local addresses:

2. Configure Postfix to Use the Map

Add the following to the bottom of the file:

Reload Postfix Configuration

Now, all email generated to non-local email addresses (i.e., anything with an @ in it) will get rerouted to the email address or distribution list you specified above.

Further Reading

  1. http://www.postfix.org/canonical.5.html
  2. http://www.postfix.org/regexp_table.5.html

Configuring Postfix on Ubuntu

I decided to make the switch from Sendmail to Postfix, and configure it on my local Ubuntu 12.04 LTS 64-bit Server VM for email testing. As has been noted elsewhere, Postfix is quite a bit easier to work with than sendmail. Since the install was on my local VM, I opted to route the Postfix traffic through Gmail’s SMTP servers using my account. Here’s how I set it up:

1. Install Postfix

When prompted, select no configuration. We will configure Postfix manually afterward.

2. Create the Main Configuration File

Populate the file with the following contents (hat tip to Matthew Hawthorne):

3. Create the Password File

Populate the file with the following contents:

Replace the user and password above with your username and password. Save the file, and then run the following command to create a hashed database file:

Now, remove the plain text password file you created so you don’t leave your credentials laying around:

4. Enable Postfix Support in PHP

Edit your php.ini file to turn on sendmail (Postfix) support:

Search for sendmail_path. It should be in the neighborhood of line 1053. Modify the line to read:

Make sure to remove the leading semicolon to uncomment the line.

5. Start / Restart Everything

Postfix didn’t start automatically when I installed it, so the start command above will start it if it is not already started. The reload command will reload the configuration if it is already loaded.

6. Test

Try sending email from a PHP application and verifying that you receive the mail. This can be as simple as writing a PHP file with the following contents and loading it in a browser through Apache or using command-line PHP to execute the file:

If you experience problems, or if the mail does not appear, you can see if Postfix generated an error by typing mailq. If, for instance, your username or password were rejected by Gmail, the mail queue would let you know. If everything works, you can stop here, or keep reading for more configuration.

7. Gotcha

I noticed that when converting from sendmail to Postfix that my local aliases file was malformed, which was preventing delivery of mail to local addresses. I fixed this issue by doing three things:

  1. Open /etc/aliases and remove the colon after postmaster
  2. Generate the aliases map file by running sudo postmap /etc/aliases
  3. Restarting Postfix by running sudo service postfix restart

8. Remap Local Users to Remote Mailboxes

I don’t actually check my mail on my local VM, so it is much more convenient to route mail that was intended for my local user account (such as when Postfix sends debug reports, for instance) to my work account. This is easily accomplished by adding a line to /etc/aliases and regenerating the aliases database.

  1. Open /etc/aliases and add localuser remoteuser@server.com (for example, kevin kfodness@example.com)
  2. Regenerate the aliases map by running sudo postmap /etc/aliases
  3. Reload the Postfix configuration by running sudo service postfix reload

Further Reading

  1. http://mhawthorne.net/posts/postfix-configuring-gmail-as-relay.html
  2. http://www.postfix.org/ADDRESS_REWRITING_README.html

Edit: I fixed an incorrect sendmail path – I forgot about the -t -i flags that are required to send mail when PHP is invoked by Apache. That’ll learn me for doing my testing on the CLI instead of through the Apache server …