[Previous] [Contents] [Next]

login

Log in (UNIX)

Syntax:

login [-f username] [-p] [-t timeout] [username]

Options:

-f username
When run as root only, force login of username.
-p
Preserve current environment variables. If -p isn't specified, the current environment will be cleared and the only environment variables set will be HOME, LOGNAME, SHELL, and those in the /etc/default/login file (these will be set regardless of whether -p is specified).
-t timeout
Cancel the login if no response is received within the specified number of seconds. A value of 0 (the default) disables the timeout facility.
username
A user's login name.

Description:

The login command starts a session associated with a user. It is used when someone either first signs on to the computer, or wishes to log in as another user. If login is invoked without an argument, it prompts for a username and password. If invoked with an argument, the argument is assumed to be the username.

The login command verifies the username and password against a password database and, if verified, starts the user session. If either the username or password is unacceptable, login will ask again for the username and password. After five unsuccessful attempts it will print the message "Login incorrect" and terminate. If the file /etc/nologin exists, users other than root will be prevented from logging in. When a user attempts to log in, the contents of the /etc/nologin file will be written to the user's terminal, and login will exit.

The login utility sets the user ID and group ID as well as the current working directory, then executes a shell according to specifications found in the password database.

If execution of the shell fails, login prints the message "No Shell" and exits. The shell is started with a dash (-) prepended to its name as argument 0. This informs the shell to perform its startup routine.

The login utility sets the HOME, SHELL, and LOGNAME environment variables. The login utility also updates system accounting information.

The login utility will also set the environment variables specified in the /etc/default/login file. This file lets you specify which environment variable settings are to be used across login sessions. If a variable isn't set when login is started and this file contains a default for the variable, that default will be used. If the file doesn't contain a default for the variable, the variable will be cleared by login. If a variable is already set when login is started and -p is specified, it is preserved, even if the /etc/default/login file contains a default for the variable. The -p option allows site-specific environment variables to be passed from the system startup processes (e.g. modem, tinit) down to applications.

The login utility may be executed only from the login shell, or when no session is active. You can't nest login commands.


Note: Since login is a shell alias for exec login, the following command won't work as expected:
on -t device login

You can use the following command instead:

on -t device /bin/login

Files:

/etc/default/login
Sets login environment variables.
/etc/passwd
Contains the user database (username, user ID, group ID, full name, home directory, shell).
/etc/shadow
Contains encrypted login password for each userid.
/etc/acclog
Accounting records are appended to this file.

See also:

logout, sh


[Previous] [Contents] [Next]