Unix Power ToolsUnix Power ToolsSearch this book

Chapter 3. Setting Up Your Unix Shell


What Happens When You Log In
The Mac OS X Terminal Application
Shell Setup Files -- Which, Where, and Why
Login Shells, Interactive Shells
What Goes in Shell Setup Files?
Tip for Changing Account Setup: Keep a Shell Ready
Use Absolute Pathnames in Shell Setup Files
Setup Files Aren't Read When You Want?
Gotchas in set prompt Test
Automatic Setups for Different Terminals
Terminal Setup: Testing TERM
Terminal Setup: Testing Remote Hostname and X Display
Terminal Setup: Testing Port
Terminal Setup: Testing Environment Variables
Terminal Setup: Searching Terminal Table
Terminal Setup: Testing Window Size
Terminal Setup: Setting and Testing Window Name
A .cshrc.$HOST File for Per Host Setup
Making a "Login" Shell
RC Files
Make Your Own Manpages Without Learning troff
Writing a Simple Manpage with the -man Macros

3.1. What Happens When You Log In

When you first log in to a Unix system, the login program performs various security measures. These vary slightly from Unix variant to Unix variant, but they are largely the same.

First, login checks to see if you are not the root user and whether the file /etc/nologin exists (it is created by the shutdown command to indicate that the system is being brought down for maintenance). If both of these conditions are true, the login program prints the contents of that file to the terminal, and the login fails. If you are the root user, however, you will be allowed to log in.

Second, login checks to see if there are any special conditions on your login attempt (which may be defined in /etc/usertty or /etc/securetty), such as on which tty you're coming in. Linux systems do this, for example. Some systems (such as Darwin and other BSD-based systems) also check /etc/fbtab and may restrict your access to any devices listed in that file. These systems may also log failed login attempts to a file, such as /var/log/failedlogin, if it exists.

login may also record the time of login in the file /var/log/lastlog, make an entry in the file /var/run/utmp, showing that you are successfully logged in (it is removed once you log out), and append the utmp entry to the file /var/log/wtmp , showing that you logged in. This wtmp record will be updated on logout, showing the duration of your login session.

If the file .hushlogin exists in the user's home directory, the login will be quiet; otherwise, the following sequence of events will occur. If the system has any special copyright information to display, it will be printed to the terminal, followed by the message of the day (usually stored in /etc/motd ), and the user's last login time and system of origin (from the wtmp file, as discussed in the previous paragraph). If you want your login to be quiet, simply touch ~/.hushlogin. If you want it to be noisy, remove the file.

Finally, if all other checks have passed and restrictions have been performed, login starts a shell for you. Which shell depends on what is set in your user database entry (/etc/passwd, NIS, or possibly NetInfo under Darwin). If the shell specified for you is not interactive (Section 3.4), you may well be denied a command line. This is common for POP and ftp-only user accounts, where /bin/true and /bin/false are often specified as shells to disallow shell logins from those accounts.

--JP and SJC

Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.