UNIX Hints & Hacks

ContentsIndex

Chapter 5: Account Management

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

5.1 User Account Names

 

5.5 GECOS Field

 

5.9 User Account Startup Files

 

5.13 Finding My Display

5.2 Passwords

 

5.6 Home Directories

 

5.10 Using Aliases

 

5.14 Copy Files to Multiple Home Directories

5.3 UID

 

5.7 Shells and the Password File

 

5.11 MS-DOS Users

 

5.15 Kill an Account

5.4 Group IDs and /etc/group

 

5.8 Configuring an Account

 

5.12 Changing Shells

 

5.16 Nulling the Root Password Without vi

 

5.12 Changing Shells

5.12.1 Description

5.12.1 Description

There is an unobtrusive way to change a shell without affecting the password file in any way.

Example

Flavors: AT&T, BSD

Shells: ksh, sh

You know that using the chsh command physically changes the password file to the shell of your choice. That command also only permits shells that are listed in the /etc/shells file. So what do you do if you want to use the bash shell and it isn't listed? There is a way around it: The following seven lines of code for the .profile startup file will have you using the bash shell every time you log in or open a new window to a shell:

if [ -x /usr/local/bin/bash ]; then
   SHELL=/usr/local/bin/bash
   export SHELL
   exec /usr/local/bin/bash
else
   echo /usr/local/bin/bash not found using default shell of $SHELL
fi

Line 1: Verify that the bash shell exists and is executable.

Line 2: If it does exist, set the variable SHELL to /usr/local/bin/bash.

Line 3: Export the variable globally.

Line 4: Start the bash shell

Line 6: If there was no bash shell, you have to use your default shell assigned to your account.

This concept can be applied to other shells with some minor changes to the syntax. Although this is good for your personal account, it is just as good for the root account if you are more comfortable working in a different shell as root. It works so well for root that, when you need to drop into single-user mode, the shell will not be located because the mount point most likely is not mounted in that mode, and the normal root shell takes over.

Reason

Everyone has a shell of choice, and this allows its use. It is unobtrusive and satisfies the needs of both the administrator and the user.

Real World Experience

This common little hack works well when it's embedded into the startup files. Also, other conditions besides the shell can be tested this way to see whether you are on a local or remote system and to execute specific commands. It gives your users freedom to start processes when they log in to a system and, when they log out, to stop them.

UNIX Hints & Hacks

ContentsIndex

Chapter 5: Account Management

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

5.1 User Account Names

 

5.5 GECOS Field

 

5.9 User Account Startup Files

 

5.13 Finding My Display

5.2 Passwords

 

5.6 Home Directories

 

5.10 Using Aliases

 

5.14 Copy Files to Multiple Home Directories

5.3 UID

 

5.7 Shells and the Password File

 

5.11 MS-DOS Users

 

5.15 Kill an Account

5.4 Group IDs and /etc/group

 

5.8 Configuring an Account

 

5.12 Changing Shells

 

5.16 Nulling the Root Password Without vi

 

© Copyright Macmillan USA. All rights reserved.