BSD DevCenter

oreilly.comSafari Books Online.Conferences.

We've expanded our LAMP news coverage and improved our search! Search for all things LAMP across O'Reilly!

Search
Search Tips

advertisement

Listen Print Subscribe to BSD Subscribe to Newsletters
FreeBSD Basics

Customizing the Login Shell

08/02/2000

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:

/stand/sysinstall

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:

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:

hostname#

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:

hostname#

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:

whoami
root
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:

hostname#

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:

$

Now,

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:

logout

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 Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com