Change a user's default shell

Feb 13, '02 08:42:59AM

Contributed by: acet

A MacOSXism that might throw more classically-aligned Unix folks is how to change a user's shell (or other passwd information, actually).

Classic wisdom suggests using standard methods such as vipw or chsh. However, these methods do not work under OS X, as I found out the hard way. If you try to use these methods which revolve around changing the passwd/master.passwd filles, you'll find that everything looks ok but that the system elements that use this information are ignoring your changes. This vexed me until I discovered that the true authoritative repository for this infomation is managed by NetInfo.

Read the rest of the article for the details on using NetInfo to change the shell, and some information on why this is advantageous over just setting the prefs in the Terminal application...

To change a users shell, one must go into NetInfo. The easiest way to do this is to use the NetInfo Manager utility which is found in the Applications/Utilities folder. Using this utility, you want to edit the property /users/joebob/shell and set it to what you want. (replace "joebob" with the appropriate user)

However, some may find a command-line alternative to this method useful. For that, use the niutil utility:

niutil -createprop . /users/joebob shell /bin/bash
Note that you want to use the short username (unix username) when you are doing this.

Some of you may wonder why you should use NetInfo Manager when you can change the shell in the Terminal preferences area. When you set the shell preference in the Terminal, you are only setting the shell that the Terminal program runs for you when it is invoked. Any other use of the shell by the system or through other means (such as, when you ssh into your box remotely) uses the shell specified in NetInfo. For instance, say you want to use the bash shell when you su to root. Setting the Terminal variable won't do that for you; when you run su, you'll find yourself as root but running the default shell of tcsh. Now, if you change the shell assigned to the root account in NetInfo, then when you su you get the shell you wanted. Same goes for other applications that can invoke shells like vi or whatnot.

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20020213084259198