- Discovering What Shell You're Using
- Understanding Shells and Options
- Changing Your Shell with chsh
- Changing Your Shell Temporarily
- Using Completion in the bash Shell
- Viewing Session History in the bash Shell
- Using Completion in the zsh Shell
- Viewing Session History in the zsh Shell
- Using Completion in the ksh Shell
- Viewing Session History in the ksh Shell
- Viewing Session History in the csh Shell
- Changing Your Identity with su
- Fixing Terminal Settings with stty
- Exiting the Shell
Changing Your Identity with su
Occasionally, you may need to log in with a userid other than your own or need to relog in with your own userid. For example, you might want to check configuration settings that you've changed before logging out to make sure that they work. Or, if you change your shell, you might want to check it before you log out (and you should do that, by the way).
You can use the su (substitute user) command to either log in as another user (Code Listing 3.15) or to start a new login shell.
Code Listing 3.15. Changing back and forth from one user to another (and exiting from multiple shells) can get a little confusing, but the prompt often tells you who you are and what directory you're in.
[ejr@hobbes asr]$ ls Projects testing [ejr@hobbes asr]$ su asr Password: [asr@hobbes asr]$ ls Projects testing [asr@hobbes asr]$ su - ejr Password: [ejr@hobbes ejr]$ ls Mail editme script2.sed Projects fortunes.copy scriptextra.sed Xrootenv.0 fortunes1.txt sedtest above.htm fortunes2.txt sorted.address.temp address.book groups temp.htm address.temp history.txt tempsort axhome html.htm test bogus html.html test2 chmod.txt mail testing.gif clean manipulate testing.wp compression nsmail typescript [ejr@hobbes ejr]$ exit [asr@hobbes asr]$ exit [ejr@hobbes ejr]$ exit
To log in as a different user with su:
At the shell prompt, type su plus the userid of the user you're logging in as. You'll be prompted for a password just as though you were logging in to the system for the first time (Code Listing 3.15).
If you do not specify a username, the system will assume you mean the root user.
If you're logged in as root to begin with, you won't be prompted to give a password.
You will now be logged in as the new user and be able to work just as if you were that user, though you'll be in the same directory with the same settings that you had before you issued the su command.
To start a new login shell with su:
su - yourid
At the shell prompt, type su - yourid (of course, use your own userid or that of the user you want to change to). The addition of the hyphen (-) will force a new login shell and set all of the environment variables and defaults according to the settings for the user.
To Return to The Previous Shell:
Type exit at the shell prompt to leave the current shell and return to the previous one. If you use exit from the original login shell, you'll log completely out of the Unix system.