NGETTY(8) | System Manager's Manual | NGETTY(8) |
ngetty - daemon for virtual console terminals
ngetty [ tty1 | vc/1 | 1 ] [ /dev/tty2 | vc/2 | 2 ] ...
ngetty-helper /dev/ttyX [ login ]
ngetty-argv :options:child:[name]:args [user [tty]]
ngetty is a daemon that starts login sessions on virtual console terminals, on demand. It opens the virtual console terminals specified by the tty... arguments, displays a /etc/issue message, prints the login prompt on each terminal and waits for user name. On user action, ngetty executes login(1) in a new process with the terminal the user is typing in as the controlling terminal.
login(1) then prompts for a password to login with the system and finally, if the login succeeds, executes the user's login shell.
When the user logs out, ngetty restarts the corresponding virtual console terminal.
Actually almost the whole work is done by a ngetty-helper program. It makes /var/run/utmp, /var/log/wtmp records, prints /etc/issue, hostname, login prompt, waits for user name. ngetty invokes the ngetty-helper by need.
The traditional way to enable logins on virtual console terminals is to start a bunch of getty(8) programs, one for each virtual console terminal, from init(8). As most users rarely login on virtual console terminals nowadays, preferring graphical logins instead, it seems wasteful to have all those getty(8) processes doing nothing but wasting memory. Alternatively, ngetty manages logins on any number of virtual console terminals from a single, light, process.
ngetty does not use stdin, stdout or stderr and closes them.
When running ngetty in the background, remember to disassociate it from the current controlling terminal by making it the process group leader of a new session, e.g.:
To start ngetty from init(8), add something like this to /etc/inittab:
If ngetty-argv is available use it to start ngetty from /etc/inittab. See the example bellow.
If ngetty can not open one of the virtual console terminals specified in the tty... arguments, most likely because that tty device node does not exist, no greeting message will be displayed on that terminal, obviously, and ngetty will simply go on, ignoring the offending terminal. Create the missing tty device and send SIGCHLD to ngetty. Then it will reopen the new tty. Instead of sending SIGCHLD you can login and logout on some working tty. This also forces ngetty to reopen the new tty.
ngetty uses ngetty-helper program. It's path is hard-coded in ngetty. Never remove ngetty-helper program nor move it to other location.
If, on user action, ngetty-helper can not execute login(1), in all likelihood because the compiled-in LOGIN path does not match your system's login(1) path, ngetty restarts the terminal and redisplays the greeting message.
In any case, ngetty does not output error messages.
It's possible to set different options for ngetty-helper program in file /etc/ngetty/Conf. If the option begin with "=" it's applied for all tty. If it start with a tty name it's applied only on current tty. Examples:
For security reasons ngetty-helper evaluate the file /etc/ngetty/Conf only if it has mode:
ngetty-helper recognizes the following options which might be embedded in the /etc/ngetty/Conf file:
If ngetty-helper finds stdout or stderr open it exits immediately with error 100. Ngetty invokes it correctly. See also the program test-helper.c in source package.
Do not edit the file /etc/ngetty/Conf directly. Put the configurations in /etc/ngetty/Conf.sed (the same syntax and permissions as /etc/ngetty/Conf) and after editing it, execute:
The script /etc/ngetty/setup removes comments, merges lines ending with a backslash and expands the string =tz=AUTO to numeric number. Then it updates /etc/ngetty/Conf.
If ngetty receives SIGTERM it kill all child's PID (first with SIGTERM and then with SIGKILL) and exit immediately. It does not change UID, GID and mode of the controlling tty devices. It does not catch the other signals. Sending SIGCHLD to ngetty forces it to reread his internal cache tables and to restart failed tty devices.
ngetty-helper recognizes the following escapes sequences which might be embedded after login-prompt=, newline=, clear= or in the /etc/issue file:
"Linux eos i386 #1 Tue Mar 19 21:54:09 MET 1996" was produced by putting "\s \n \m \v" into /etc/issue.
The program ngetty-argv(8) splits argv[1] on strings,
expands %U and %T to username and tty and then start the the
application. The first char after "login-argv=" is split char. In
the examples above every user logs on tty4 without password and tty5 is
always root. To understand better how ngetty-argv works try as
non-root:
ngetty-argv ':/bin/echo:echo:%U: on %T' usr tty3
ngetty-argv ':/bin/sleep:-hacker:39:I am %U on %T' 123 X
One possible example for /etc/ngetty/Conf is:
Another example is setting the TTY environ automatically:
I recommend using ngetty-argv in /etc/inittab also. Put as last argument runlevel string. Then ps will show ngetty-2345 instead of ngetty. Next start tty1 ... tty6 on runlevels 2345.
On a terminal (in scripts) start ngetty with
This program is a hack written for ngetty-helper. There is no additional code in ngetty-helper and it's possible to start a program with any args. It is like a filter between ngetty-helper and login application. One can easy modify it without touching ngetty-helper. It's similar to DJB well known argv0(1) and setuidgid(8). You can write own such programs and use them instead of ngetty-argv.
/etc/ngetty/Conf | ngetty-helper configuration file |
/etc/ngetty/Conf.sed | private setup file |
/etc/ngetty/setup | updates Conf.sed -> Conf |
/etc/issue | printed before the login prompt |
/var/run/utmp | the system status file |
/var/log/wtmp | the system logging file |
/etc/inittab | init(8) configuration file |
getty(8) fgetty(8) mingetty(8)
login(1) nlogin(1) argv0(1) setuidgid(8)
stty(1)
http://sites.google.com/site/anbadeol/logind
Nikola Vladov
http://riemann.fmi.uni-sofia.bg/ngetty/
Copyright 2007,2008,2010 Nikola Vladov
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
May 2010 |