Sunday, May 9, 2010
Monday, January 12, 2009
Kerberos for SSH authentication
1) I could get Kerberos tickets using both the GUI and kinit (i.e. they show up in klist) using my user
2) It used to work just fine
3) It worked correctly on my machine if I log in as a newly created user
4) For some reason, when I made ssh verbose, I had
debug3: preferred publickey,keyboard-interactive,password
... as my user, but as a different user (which worked) I had
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
(gssapi should be Kerberos)
5) ssh keys didn't work either
6) my /etc/ssh_config file and other configuration looks fine
It turned out that MacPorts was to blame. Running `which ssh` in my account gave:
/opt/local/bin/ssh
On the other had, a newly created account would have:
/usr/bin/ssh
The fix is to change $PATH, of course. However, I'm not sure why some MacPorts package would have installed SSH as a dependancy.
Time spent: most of the morning (~3 hrs)
Tuesday, August 19, 2008
AFP vs SMB
Time spent: around a week of getting frustrated on and off. :)
Monday, August 18, 2008
Smart Power Strips in OS X
I recently purchased a Philips Smart Surge Protector (SPP3225WA/17). It’s nice because it can detect when an attached device is turned off and then turn off any other devices attached. This is especially useful when used with a computer because most peripherals are unusable when the computer is off, so there’s no sense in leaving them on.
It’s a great idea in theory, but I had problems using it with my Mac mini (OS X Leopard 10.5.4). Specifically, I want to use the built-in power scheduling (see “Energy Saver” -> “Schedule…” in System Preferences) to have the Mac turn off everything so we don’t have to remember to do so at the end of the day. Everything worked fine using the normal “Shut Down” command, but I didn’t want to have to make sure no one was doing anything every night. I wanted to use something like “Sleep”, but unfortunately, once the Mac went to sleep, it would turn off the attached external hard drives which would, in turn, wake the Mac back up. (It would also complain about not being properly ejected.) The most the Mac would stay asleep would be a couple of seconds.
But, I found a solution! According to some information I found, there’s a way to change from using the default “sleep” and use something closer to what Windows users may know as “hibernate”. (It exists normally in OS X, but is only triggered by low battery.) To force it to always “hibernate” when sleeping (which is fine in the case of the Mac mini), you can run the following command at the command line:
sudo pmset -a hibernatemode 1To reset this back to normal, run:
sudo pmset -a hibernatemode 3Using this hibernate mode, the Mac no longer turns itself back on when the power to the external hard drives goes off. You can then set the Mac to sleep on whatever schedule works for you in System Preferences and everything else should turn off around 15 seconds after it starts going to sleep. (You’ll have to give it a little bit because it has to write the contents of memory to disk, which takes time.)
However, one problem still remains: OS X will still complain about the disks being removed improperly. To get around this, I wrote a small shell script which ejects them 5 minutes before the scheduled sleep time. You’ll need to tailor it to your setup, of course.
#!/usr/bin/env bash
# ~/bin/eject_external_drives
if [ -d "/Volumes/Time Machine" ]
then
diskutil eject "/Volumes/Time Machine"
fi
if [ -d "/Volumes/Storage" ]
then
diskutil eject "/Volumes/Storage"
fi
My crontab for this task looks like so:
55 11 * * * /Users/ben/bin/eject_external_drives
50 11 * * * /Users/ben/bin/eject_external_drives
(It tries twice before midnight.)
I haven’t used this extensively yet, but it seem to be working well in testing so far. Let me know if it works for you!
Wednesday, August 13, 2008
NULL (nil) in fixtures
I was developing against SQLite for a while and didn’t notice that I had accidentally put "NULL" (i.e. as a string) in the fixtures. SQLite didn’t care about this, but MSSQL certainly did. Because I specified constraints on the column widths, I got the error:
ActiveRecord::StatementInvalid: DBI::DatabaseError: 22001 (8152) [FreeTDS][SQL Server]String or binary data would be truncated.At first I thought you had to use nil in fixtures, but in fact, it’s actually NULL that you want.
Time spent: 15 mintues, mostly because our tests run really slow right now (any tips?)
Tuesday, August 12, 2008
It took quite a while to figure out that Time objects aren't treated exactly as you might expect when using :conditions in a find or named_scope. From what I can tell, without extra help, Time objects are just treated as dates. This is fine if you're checking conditions like I was outside the same day, but not if they are in the same day. This came up in writing a unit test for a model. My tests for the named scopes weren't testing within the same day (i.e. only for values like 2.days.ago), so they passed, but other tests that expected to be able to set the open and close dates to a time within the same day would fail (confusingly).
So, it was incorrect to use the following, because Rails was treating them like dates instead of datetimes.
named_scope :active, lambda { now = Time.now; {:conditions => ['? > open_date and ? < close_date', now, now] } }
Instead, the following was used to make sure the time parts are included.
named_scope :active, lambda { now = Time.now; {:conditions => ['? > open_date and ? < close_date', now.to_s(:sql), now.to_s(:sql)] } }
Time spent: ~1.5 hours