BSD DevCenter
oreilly.comSafari Books Online.Conferences.


FreeBSD Basics

Customizing the Login Shell


For those users whose first operating system was not Unix, the concept of different login shells can be very confusing. It can take some time before you can consistently remember how to figure out which shell you are in, know which shells should be used for which purposes, and become comfortable with the features of each shell.

This article won't cover shell scripting or advanced shell tweaks; instead we'll concentrate on some differences between the C and Bourne shells. We'll also cover editing login and logout scripts, and learn something about login and non-login shells along the way.

By default, on a FreeBSD system, root's login shell is csh (the C shell) and all other users are given a default login shell of sh (the Bourne shell). If you haven't customized your prompt, its appearance is a clue to which shell you are using. To test this, let's make two users. Log in as root and type:


and select "Configure," "User Management," and then "User."

Note that the only section filled in is the Login shell field; it shows the default of a new user as /bin/sh.

Create a user called test1, add the user to the wheel group, assign a password you'll remember, and tab over to "OK" to add the user.

Create a second user called test2, add the user to the wheel group, assign a password, but this time change the Login shell field to read /bin/csh. Then tab over to "OK" to add the second user.

Exit /stand/sysinstall and type the word logout. Your prompt should now look like this:


Login as test1 and you'll receive the Bourne shell which looks like this for a normal user:


Now, su to root to see what the shell looks like to the superuser:


Note that hostname will be replaced with the hostname of your computer.

Open up another virtual terminal that has the login: prompt. This time, log in as test2 to see what the C shell prompt looks like to a regular user:


Now, su to root to see what the shell looks like to the superuser:


Note that both superuser's prompts look the same. So how do you tell which user has which login shell? Try this:

grep test* /etc/passwd
test1:test1:*:1005:0:User &:/home/test1:/bin/sh
test2:test2:*:1006:0:User &:/home/test2:/bin/csh

You may have noticed when you logged in as test2 that you received a humorous fortune; however, test1 and both superusers did not. Before we discuss why, if you type logout as either superuser, you should get this error message:

Not a login shell.

and you'll still have the same prompt. To leave superuser, you must type exit. Then test1 should be back here:


(the Bourne shell) and test2, who has the C shell, should get this prompt back:


Let's try this one more time; have test1 su to root, then:

grep root /etc/passwd
root:*:0:0:Charlie &:/root:/bin/csh

If test2 does the same thing, you should get the same results. The reason why both the superuser's prompts looked the same is that they both received root's default C shell.

Now for the login shell error message. Open up another virtual terminal with a login: prompt and log in directly as root.

Since root's login shell is the C shell, you should receive a fortune and a prompt that looks like this:


Now type logout. You should receive the login: prompt back without any error messages.

This is an important concept. You can only logout of a terminal that you login to. If you su to another user, you will receive that user's default shell, but it will be as a non-login shell. The only way to exit a non-login shell is with the exit command.

Open up yet another virtual terminal with a login: prompt and log in as test1. Your prompt should look like this:



su test2

and enter the password for test2 when prompted. Your prompt should change to this:


Note that your shell has changed from the login Bourne shell to the non-login C shell. If you type:


you will see

Not a login shell.

However, if you type exit, your prompt changes back to


Now type logout -- you should see:

logout: not found

What happened now? You are in the Bourne login shell but it seems to have "lost" the logout command! We better try a:

man logout

If you go down a page, you'll see a list of commands and a comparison of those built into the C and the Bourne shells. Note that the C shell supports many more commands than the Bourne shell. Finally, note the Bourne shell's lack of built-in support for the logout command. The only way to leave the Bourne shell is with the exit command.

Pages: 1, 2

Next Pagearrow

Sponsored by: