Dum Pendebat Filius

A sniff in the kortevar, that what you cry for, yeled? A prert up the cull, a prang on the dumpendebat?

Changing root’s shell

Here, readers, is a question I’ve been pondering for some time. I am addressing this question to the subset of my readers who have anything to do with commercial flavors of UNIX, a subset which I imagine is extremely small.

The question periodically appears and re-appears on mailing lists: How do you change root’s shell?

To me, that question is easily answered: Why in the world would you want to?

You see, there’s a reason how come root’s login shell is set to /sbin/sh, the good old Bourne shell. (This is the case on Solaris systems, that is; HP-UX uses the “POSIX shell” instead. To keep it simple, let’s restrict this discussion to Solaris.)

Time and again, someone writes a note to the mailing list, saying, Boy, does that Bourne shell suck. What were they thinking? When I log in as root, I want to use bash instead. How do I do that? Can I just edit the line in /etc/passwd?

This usually sparks a discussion, over the course of several days, about Yes you can and No you can’t, and impassioned complaints about the Bourne shell’s lack of user-friendliness (No filename-completion! No command-history editing mechanism! No fc-editor! Baroque syntactical rules!), and soon they’re talking about statically-linked versus dynamically-linked binaries, and sometimes people even start talking about recompiling bash so they can relink the damn thing.

This is silliness.

First of all, /sbin/sh is there for a reason. It’s a statically-linked binary. As long as you can mount the root file system, you’re guaranteed access to that shell. /bin, you’ll notice, is a symbolic link to /usr/bin. Where are the other shells located?

  • Korn shell: /bin/ksh
  • C shell: /bin/csh
  • Bash (my personal favorite): /bin/bash

And so forth. A shell, remember, is just another executable binary. And except for /sbin/sh, they all live on a non-root file system.

Unless you like to live dangerously, you’ve set up /usr as a separate file system. So, what if, one day, shit goes pear-shaped and /usr gets corrupted and needs to be fsck‘ed, and you, addicted to filename completion and event designators, have changed root’s login shell to /bin/bash? Now your login shell is in a corrupted file system. How are you going to log in without a valid login shell? Oops.

The thing is, I completely understand where you’re coming from when you tell me that /sbin/sh is a crappy shell to be interacting with, and I agree with you wholeheartedly. I promise you, nobody likes those extra features (filename completion with TAB, history substitution, job control, etc.) that come with a modern shell like bash or tcsh more than I do. If I’m going to be typing more than two or three commands, I want to be using bash, too. I’ve been a fan of bash for eleven years now. So, you ask, what do I do?

It couldn’t be simpler, readers. Log in as root, then do this:

# exec /bin/bash --login

Simply substitute (via exec) an instance of bash, invoking it as a login shell (with the --login argument), for the current shell.

That’s all you have to do: type in one extra command, and you’ve got exactly what you want. Go ahead and create a .bash_profile for root and customize it the way your heart tells you to. If you invoke bash as a login shell, it’ll do just what you want it to.

So, why would anybody waste their time trying to change root’s login shell?

Just use exec to run the shell of your choice whenever you want to.

Filed under: Tech by dumpendebat at 2005/09/05 - 21:57

No Comments »

No comments yet.

RSS feed iconRSS feed for comments on this post

Trackback URI for this post

<< Back to homepage

Leave a comment

Line and paragraph breaks are automatic. Your email address is never displayed.

Do not paste an entire article or blog post into here: create a link to it (or at least create a tinyurl) instead.

The following HTML tags are allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>