Archive

Posts Tagged ‘Mac OS X’

Using SSH to bypass The Great Firewall/GFW

December 9th, 2009

This looks like a long process, how does it work after I’m done?

  • You’re ssh tunnel to your server outside the GFW will be active *whenever* your online
  • When you need to bypass the GFW, simply select “SSH” from your locations menu
  • When you don’t need to use your proxy, simply switch your location back to Automatic

What you need:

Configuring SSH key based authentication can be very difficult if you haven’t configured it previously. The idea is:

  • Generate a key set on your local computer (with ssh-keygen on the local system)
  • The Key Set will make two files on your hard drive, a “Private Key” and a “Public Key” (~/.ssh/id_rsa.pub on the local system)
  • Note that the “Private Key” is many “lines” long, but the “Public Key” is a single line (no newlines/returns)
  • The server that you’re logging into keeps a list of keys that are authorized to access the system (in ~/.ssh/authorized_keys on the server)
  • Copy the single line of your “public key” file onto any line of your “authorized keys” file.
  • Make sure the permissions of both your public keys and private keys are “correct”. “Insecure” file permissions are the most common cause of SSH key’s failing to authenticate.
  • Always keep your .ssh dir and all your keys chmodded to 700 and 600 respectively.
  • Use “ssh -vvv” if you have trouble logging in, this will give you diagnostic output.

Verify that you’re able to connect to the system you’ll be using to proxy via SSH.

If you’ve got the Apple Developer Tools installed, then go directly to the AutoSSH website, download the source, compile and install. In case you don’t, I’ve complied a copy that you can download here.

Just extract with:

tar zxvf autossh.tgz -C /

Use foreground mode to verify that you’re able to connect to the system of your choice via AutoSSH.

autossh -M 19999 -D 9999 -N example.com

Use cURL to verify that your proxy is working

curl —socks4a localhost:9999 -v www.facebook.com

Now that your proxy is online, the next step is to define a new location in your Mac OS X “Network” Profiles.

In System Preferences / Network:

  • From the Locations dropdown choose “Edit Locations” then add a new location called “SSH”
    Screen shot 2009-12-01 at 上午01.07.36.png
  • Return to the main Network window and choose “Advanced” then “Proxies”
    Screen shot 2009-12-01 at 上午01.07.28.png
  • Enable “SOCKS Proxy” setting the proxy server to “localhost” and port “9999”
    Screen shot 2009-12-01 at 上午01.08.09.png
  • Under bypass proxy setting for these hosts and domains, you can enter any sites that will be slowed down by proxing via your SSH connection:
    *.local, 169.254/16, *.cn, *.163.com, *.baidu.com, *.youku.com, *.toudou.com, *.sina.com, *.chinesepod.com

Last, we just need to configure autossh to start when our Mac boots up. We’ll use a Login Hook so that the script will run regardless of which user logs in.

http://support.apple.com/kb/HT2420

You’ll need to create the shell script to use as the Login Hook, save it as /usr/local/bin/loginhook, and make it executable (chmod 755).

    #! /bin/bash</p>

<pre><code>if [ &amp;quot;$(ps ax | grep autossh | grep -vc grep)&amp;quot; -lt 1 ]; then
  sudo -u {USER} /usr/local/bin/autossh -f -M 19999 -D 9999 -N -o ServerAliveInterval=3 {SERVER}
fi
</code></pre>

<p>

If you have trouble connecting and need to debug the autossh line, first try disabling the “-f” so that the program runs in the foreground and returns output. If you need to send the output to a log file, you can edit the loginhook script to something like:

sudo -u {USER} autossh -M 19999 -D 9999 -N {SERVER} 2&amp;>1 &gt;&gt; /tmp/loginhook.log

(Note that you’ll need to replace {USER} with the short name of the user account that is providing the SSH public key and {SERVER} with the host your connecting to)

sudo defaults write com.apple.loginwindow LoginHook /usr/local/bin/loginhook

If your ever in doubt as to weather or not your new Proxy is running correctly, save the following script as /usr/local/bin/gfw. Run this script to instantly check on the status of your proxy.

curl --socks4a localhost:9999 -v www.facebook.com

Reboot, Test and Enjoy!

ryan Uncategorized (无大类) ,

Languages in Snow Leopard (Finder Info Window)

September 15th, 2009

200909160112.jpgIn Mac OS X Leopard (10.5) and earlier, the Finder “Info” window for an application would allow you to enable and disable specific language packs. This was probably one of the least frequently features of the finder for average users, and so it was removed in Snow Leopard.

Unfortunately, I used that feature all the time :-) Primarily to disable the horrendous Chinese localization (halfway done) that is Adium. For me, reading Chinese is easy and reading english is even easier. But when a set of menus is half Chinese/half english, then my eye just automatically skips over the Chinese part, skipping to the english part I can read without even thinking…

There is a FREE utility that you can download to get this functionality back. It’s called “Language Switcher“. Language Switcher will even allow you to launch two instances of an application, both in different languages. Take a look!

200909160115.jpg

ryan Uncategorized