login
This subchapter looks at login and logout, a pair of UNIX (and Linux) commands.
NOTE: On a single-user Linux or Mac OS X desktop/laptop computer, you can start the Terminal program and be automatically signed in (no need for account login or password). On a remote server, you will always need to login in with at least account name and password.
login
login is a UNIX command for logging into a UNIX system.
login is a builtin command in csh. There is also an external utility with the same name and functionality.
In many modern systems, the functionality of login is hidden from the user. The login command runs automatically upon connection. In some old computers you may need to type a special character or even type login to bring up the login program.
If you login remotely to a server you will be prompted for your user/account name and password. If you start up a terminal emulator and shell from a graphic user interface you will probably already be authenticated and immediately go to the shell (although some of the startup activity of login will still be done for you).
The activities that login performs at startup of a shell will be covered in a later subchapter, because you need more familiarity with the shell before you can understand that material.
Starting a shell is covered in the previous subchapter about shell basics.
select system or host
If you are signing into a system that combines multiple computers, you will first need to indicate which computer you are logging into.
You may already be logged in if you are using a terminal emulator on a personal computer or workstation. If so, you dont need this step.
You will see a prompt indicating a choice of computer, such as (only one of these will appear):
host:
pad:
request:
system:
You will see only one of these (or similar) choices.
If you see login: instead, then you dont have to worry about choosing the system.
Enter the identifying name of the computer system you were assigned to use, followed by the ENTER or RETURN key. Your system administrator can provide you with this information.
On some networked systems you can abbreviate with the first two or three characters of the computer name (as long as it is enough to uniquely identify which computer is intended).
If you are successful, you will be presented with the login: prompt.
account name
You may already be logged in if you are using a terminal emulator on a personal computer or workstation. If so, you dont need this step.
Ask your system administrator for your account name. If this is your own personal system, then use the account name set up during installation. Many modern install disks include a utility for creating a new account.
At the login: prompt, enter your account name, followed by the ENTER or RETURN key.
Type your account name in lower case letters. UNIX assumes that an account name in ALL CAPITAL LETTERS indicates an old input/out device that doesnt support lower case letters (such as an old style teletype, or TTY). Also, if you use upper case letters for the login, then you can not use lower case letters in the password.
If you enter a valid account name, you will be asked for your password. On many computers, you will be asked for a password even if you enter an incorrect account name. This is a security measure to help prevent guessing account names.
login: accountname
Password:
See the subchapter on login and logout for more information.
password
You may already be logged in if you are using a terminal emulator on a personal computer or workstation. If so, you dont need this step.
Ask your system administrator for your password. If this is your own personal system, then use the password set up during installation. Many modern install disks include a utility for changing the password for an existing account or for creating a new account with a new password.
At the Password: prompt, enter your password, followed by the ENTER or RETURN key.
Password: password
$
In some cases, a new account doesnt have a password. Also, it is common for Mac OS X to have no password for the user account.
If your account doesnt have a password, just press the ENTER or RETURN key.
Change your password to a secure password at your earliest opportunity. If you dont know how to do this yet, the upcoming subchapter on passwd (yes, that is the correct spelling) will tell you how. That same subchapter gives advice on how to select a secure password.
Failure will be indicated by an error message. The exact error message varies by system, but will probably be something similar to:
Login incorrect
The most likely reasons are:
- Incorrect account name.
- Incorrect password.
- You typed the account name in upper case letters (check the CAPS LOCK key).
You should have a new login prompt and can easily start over.
If you logged in in upper case, the shell will display in upper case letters and expect you to type only in upper case letters.
If you accidentally typed the account name in upper case letters, but havent yet typed in the password, many UNIX systems will display aa backslash character in front of the password prompt.
If you realize you made a mistake on the account name and want to start over, hold down the CONTROL key (often marked CTRL) and the D key at the same time. This will stop the login program and start over again from the beginning.
Note that at one time there was a security hole because of the Control-D. A hacker would start the login, type Control-D, and then try to slip in a command to the shell before a new login program could be started. This security hole no longer exists on shell login, but this same type of timing attack is still used for other security holes.
terminal type
On some older UNIX systems you may be asked to provide the terminal type you are using. Some modern terminal emulator programs offer the choice of emulating various different terminals from the early UNIX era. These different terminal types had different specialized capabilities.
Because the early traditional UNIX was created primarily on Digital Equipment Corporation (DEC) computers (first the PDP, followed by the VAX), the default terminal device was the DEC VT100. Most modern terminal emulator programs act like the VT100.
On older UNIX systems you may see the terminal type prompt:
Term:
In some cases, the prompt may give the default terminal setting in parenthesis.
Term = (VT100)
If the default terminal setting is correct, simply press the RETURN or ENTER key.
Otherwise, type in the correct terminal type, followed by the ENTER or RETURN key.
If you are uncertain, try the vt100 or UNKNOWN, followed by ENTER or RETURN.
Some common terminal types:
After you are logged in, you can set the terminal type (capitalization matters).
Shell |
Command |
csh or tcsh |
setenv TERM vt100 |
sh |
TERM=vt100; export TERM |
ksh , bash , or zsh |
export TERM=vt100 |
VMS |
set term/device=vt100 |
If you do not know your shell type, use the following command (followed by ENTER or RETURN):
$ echo $SHELL
You will need to enter the appropriate command each time you login.
Alternatively, you can add the appropriate command line to the initialization file in your home directory.
Shell |
Login file |
csh |
.cshrc or .login |
tcsh |
.cshrc |
ksh |
.profile
.kshrc |
zsh |
.zshrc |
bash |
.bash_profile |
remote shell |
.rhosts |
VMS users need to modify the login.com file, adding the line $set term/device=vt100
.
logout
When you finish using the shell, type the exit or logout command. This will either display a new login prompt or close the terminal emulator window. if you are logged in remotely to a server, this will break your connection. If you are logged in physically on a large UNIX system, this will prevent someone else from abusing your account.
When you finish using the shell, type the exit or logout command. This will either display a new login prompt or close the terminal emulator window.
Some of the possible variations of this command include: bye, exit, lo, logout, and quit.
Typing CtrlL-D (holding down the CONTROL key and the D key at the same time) will also log you out of most shells. The Ctrl-D tells the shell it has reached the end-of-file (EOF). Because the shell is a filter and filters terminate when EOF is reached, the shell terminates and you log off the system or return to the parent process.
While it might not be a big deal to skip this step on a single user computer that you never leave unattended, forgetting to logout from a remote server is a serious security hole. If you leave your computer or terminal unattended, someone else can sit down and gain access to all of your files, including the ability to read, modify, or delete them. The imposter can send spam emails from your user ID. The imposter can even use your computer or account to attempt to hack or damage or break into any system in the world from your user ID. If this occurs from a school or business account, you will be responsible for any damage done.
Most modern systems accept either logout or exit.
On Mac OS X, typing logout produces the following result:
$ logout
[Process completed]
On Mac OS X, typing exit produces the following result (notice that the shell automatically runs logout for you):
$ exit
logout
[Process completed]
A successful logout will stop all running foreground or background processes. There is a way to keep processes running, which is useful for things like starting up your Apache web server and MySQL data base, but the method will be discussed later.
If you see the message There are stopped jobs. it means that you have one or more suspended jobs. The shell is letting you know in case you forgot about them. If you type logout again without running the jobs in between, the system will go ahead and log you out and terminate all suspended jobs.
logout is a builtin command in csh.
exit
exit is a built-in shell command (for the shells that support it), while logout is a program. In the csh (C Shell), logout is an internal built-in command. sh (the original Bourne shell) and ksh (the Korn Shell) do not officially have the logout command, but many modern versions support it.
exit can be used by itself as a substitute for logout (as mentioned above).
exit can also be used to send a return value (often an error code) to the parent process. Simply add an integer following exit. This is particularly useful in scripting.
$ exit n
exit will be covered later in its own subchapter.
comments, suggestions, corrections, criticisms
free music player coding example
Coding example: I am making heavily documented and explained open source code for a method to play music for free almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).
View music player in action: www.musicinpublic.com/.
Create your own copy from the original source code/ (presented for learning programming).
Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.
Names and logos of various OSs are trademarks of their respective owners.