Tuesday, April 3, 2007

Enable auto login via command line [update]

I have been wondering on how to do this for a long time.

Here's the clue:
On Mac OS X Server side there is this tool:
/System/Library/ServerSetup/serversetup

Amongst a lot of other features, it offers these functions:

serversetup -setAutoLoginUser Name UID Password
Set the autostart user using the name and password supplied.

serversetup -getAutoLoginUser
Returns the current AutoLoginUser.

serversetup -clearAutoLoginUser UID
Disables AutoLogin feature.

Now what if I copied this tool to a Mac client?
Guess what...

It works. Well sort of. Sometimes.
It works if the script is executed while logged in locally on the machine.
But that's not what I want.

But I found another hint here:

http://www.applescript.net/viewtopic.php?id=17957

What you can do is copy the file/private/etc/kcpassword generated on one machine to all the macs you want to log in automatically. It contains an encrypted password. Unfortunately there is no documented way of generating this file on a client. Hmm.

Then all you have to do is change the login preferences by issuing the following commands:

/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser yourusername
/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUID yourUIDnumber

[update]
There is a cooler way to do this.
I found a utility whose name is 'kcpasswd'.
kcpasswd is a command line application that changes a user's KeyChain password.
That's not exaclty that I was looking for, but it comes real close.
So I sent an email to the author of 'kcpasswd' if there were any chance that he could support generating the /etc/kcpassword file.

After a while I received an email from Phill Tejada telling me that he had this new tool called 'loginoptions' which does just that.
Way cool and thanks a lot Phill.

Oh yes, the links, I almost forgot:
FruitBatSoftware
loginoptions

3 comments:

Unknown said...

Hi... I am looking to download kcpasswd and loginoptions, but the developer's site is now down. Do you have a copy, or perhaps able to put me in contact with the developer to find a copy of these apps?

arklight said...

I am also looking for this app. kcpasswd

could you please send me information on where to download or maybe email it to me. I am desperate.

Gili said...

It looks like https://github.com/xfreebird/kcpassword will do what you want.