NGETTY(8)
π NGETTY π
the daemon for virtual console terminals β straight out of the System Manager's Manual, section 8, bestie. Buckle up, this one's a whole era. β¨
πΈ SYNOPSIS πΈ
ngetty [ tty1 | vc/1 | 1 ] [ /dev/tty2 | vc/2 | 2 ] ...
ngetty-helper /dev/ttyX [ login ]
ngetty-argv :options:child:[name]:args [user [tty]]
π¦ DESCRIPTION π¦
okay so. ngetty is a daemon that spins up login sessions on virtual console terminals on demand. It opens the virtual console terminals you listed in the tty... arguments, shows a /etc/issue message, drops the login prompt on every terminal, and then just... waits for a user name. π«Ά
The moment a user does something, ngetty runs login(1) in a brand new process, with the terminal the user is typing in as the controlling terminal.
Then login(1) asks for a password so you can actually log into the system, and finally β if the login goes through β it runs the user's login shell. π
When the user logs out, ngetty restarts that corresponding virtual console terminal. Iconic behaviour honestly.
ngl, almost the entire job is actually done by a ngetty-helper program. It makes the /var/run/utmp and /var/log/wtmp records, prints /etc/issue, the hostname, the login prompt, and waits for the user name. ngetty invokes ngetty-helper whenever it needs it. Teamwork, periodt.
π HISTORY π
The traditional way to enable logins on virtual console terminals is to start a whole bunch of getty(8) programs β one for every single virtual console terminal β from init(8). But bestie, most users barely even log in on virtual console terminals nowadays, they're all about graphical logins instead. So having all those getty(8) processes just sitting there doing absolutely nothing but wasting memory? Wasteful. π
ngetty, on the other hand, manages logins on any number of virtual console terminals from a single, light, process. Lowkey a glow-up.
β¨ INVOCATION β¨
Heads up: ngetty does not use stdin, stdout or stderr β it closes them. Not me ghosting the standard streams. π
When you're 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, like this:
setsid ngetty tty... &
ngetty-argv :-D:-S:-e:--:/usr/sbin/ngetty::1:2:3:4
To start ngetty from init(8), add something like this to /etc/inittab:
ng:2345:respawn:/usr/sbin/ngetty tty1 tty2 ... tty6
If ngetty-argv is available, use it to start ngetty from /etc/inittab. There's an example below. π
π₯ DIAGNOSTICS π₯
If ngetty can not open one of the virtual console terminals you named in the tty... arguments β most likely because that tty device node does not exist β then no greeting message gets displayed on that terminal, obviously, and ngetty will simply go on, ignoring the offending terminal. No drama, it just moves on. π
Fix it like this: create the missing tty device and send SIGCHLD to ngetty. Then it will reopen the new tty. And instead of sending SIGCHLD, you can also just login and logout on some working tty β that also forces ngetty to reopen the new tty. Two paths, both slay.
ngetty uses the ngetty-helper program. Its path is hard-coded in ngetty. Never remove the ngetty-helper program and never move it to another location. Fr fr.
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 β then ngetty restarts the terminal and redisplays the greeting message. π
In any case, ngetty does not output error messages. It's giving silent, mysterious, main character energy. π€«
π OPTIONS π
It's possible to set different options for the ngetty-helper program in the file /etc/ngetty/Conf. If the option begins with = it's applied for all tty. If it starts with a tty name it's applied only on the current tty. Examples:
# options format:
# [ttyX]=option[=value]
#=debug
=environ=,TERM=linux
tty3=long-hostname
tty1=clear=\033c
=newline=
=timeout=180
tty1=timeout=60
tty1=delay=1
For security reasons, ngetty-helper evaluates the file /etc/ngetty/Conf only if it has this mode:
-rw------- root root /etc/ngetty/Conf
π no group, no other, nobody peeking. keep it locked down bestie.
ngetty-helper recognizes the following options, which might be embedded in the /etc/ngetty/Conf file:
# tty5=login-prog=/bin/login.testβ If a line starts with#, space or tab it is a comment. π¬debugβ Ifdebugis set,ngetty-helperwrites on the terminal all successfully applied options. Set this on the fist line of the/etc/ngetty/Conffile. πdate-stringβ Escape\d(current day) in/etc/issueas:Fri Jun 01 2007. Default is:2007-06-01.days=stringβ Abbreviation for week days (21 bytes). Default is:=days=SunMonTueWedThuFriSatmonths=stringβ Abbreviation for months (36 bytes). Default is:=months=JanFebMarAprMayJunJulAugSepOctNovDectz=stringβ Change the timezone offset. If the string starts with slash it's the name of the tzfile. The string is a positive number if the local time zone is east of the Prime Meridian and negative if it is west. Default is/etc/localtime. Examples:
=tz=-18000 -0500
=tz=7200 +0200
=tz=/etc/localtime
=tz=AUTO
echo-offβ Turn the echo off just before starting/bin/login. It's similar tostty -echo.newline=stringβ Print this string before writing out/etc/issue. (default is\012). Example:tty3=newline=\012I am \l\012clear=stringβ Clear the screen before prompting for the login name with the string (default is\033c). Examples:
tty1=clear=
tty3=clear=\033[H\033[J
noclear-first=/etc/ngetty/.noclearβ Do not clear the screen before prompting for the login name the first time after reboot. Example:tty1=noclear-first=/etc/ngetty/.noclear.tty1nohangupβ Do not callvhangup()to disable writing to this tty by other applications.long-hostnameβ By default the hostname is only printed until the first dot. With this option enabled, the full text fromgethostname()is shown. πnousernameβ Do not ask for user name. Execlogin(1)immediately. Example:
=nousername
=login-prompt= Press ENTER to activate \l
deny=,black,list,users...β Disable login process for some users. The first char afterdeny=is split char. Example:tty1=deny=,root,nobody,guestallow=,white,list,users...β Enable login process only for the users. The first char afterallow=is split char. Example:
=clear=
=allow=,root,operator
print=an:CM:PY:04:69β Accept only these chars in user name. Default is to accept only",-._ 0-9 a-z A-Z". It's possible to insert here the output ofprintf 'tty3=print=az:AZ:\ABC\XYZ:__'β hereABCandXYZare octal numbers. Examples:
tty1=print=az:AZ
tty2=print=az:AZ:__:,.:09
issue-file=/etc/issueβ Change the issue file. Disable printing of the issue file with:=issue-file=login-prog=/bin/loginβ Change the login app. It's possible to use fgetty's/bin/login1application with:
=echo-off
=login-prog=/bin/login1
login-buffer=stringβ Read login name over the string. Default string is 40 bytes long. Example:=login-buffer=12345678901234567login-prompt=\n login:β Change the login prompt string. Example:=login-prompt=\033[1;33m\l\033[0;39m \n login:nice=10β Change the priority by callingnice().delay=5β Sleep this many seconds before printing the file/etc/issue.timeout=180β Wait at most this many seconds for user name. β³chdir=/homeβ Change into this directory before calling the login prog.chroot=/chrootβ Callchroot()with this directory name.autologin-name=usernameβ Log the specified user automatically in without asking for a login name and password. Check the-foption from/bin/loginfor this. Example:tty1=autologin-name=mariaautologin-first=/etc/ngetty/.autologinβ Log in automatically only the first time after reboot without asking for a login name and password. Example:
tty1=autologin-name=maria
tty1=autologin-first=/etc/ngetty/.autologin
environ=,TERM=linuxβ Replace the environ. The first char afterenviron=is split char. Examples:
=environ=,TERM=vt100,PATH=/bin:/usr/bin,HOME=/
tty3=environ=,TERM=linux,TTY=/dev/tty3
sh-A=lineβ Exec this line before printing/etc/issue. The line is executed using/bin/sh -c line. It's a good idea to use the full paths here. Example:
tty4=sh-A=exec /bin/ps e -u root
tty4=delay=8
sh-B=lineβ Similar to optionsh-A. This is executed before asking for username.login-argv=any_stringβ Ngetty starts the login application with options:
login -- XYZ # default
login -f XYZ # if autologin-name=XYZ
With this option it's possible to start the login appl with any_string instead of -- or -f. Using the program ngetty-argv(8) one can start an arbitrary program with different arguments. Two very dangerous examples are (never try them):
tty4=login-prog=/usr/sbin/ngetty-argv
tty5=login-prog=/usr/sbin/ngetty-argv
tty4=login-argv=,/bin/login,,-f,%U
tty5=login-argv=:-C:/bin/bash:-bash
π bestie I am BEGGING you, do not run those. that's not a vibe check that's a vibe detonation.
π WARNING π
If ngetty-helper finds stdout or stderr open, it exits immediately with error 100. ngetty invokes it correctly, so like, don't worry about it β but know it. See also the program test-helper.c in the 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:
cd /etc/ngetty && ./setup
The script /etc/ngetty/setup removes comments, merges lines ending with a backslash, and expands the string =tz=AUTO to a numeric number. Then it updates /etc/ngetty/Conf. β¨
β SIGNALS β
If ngetty receives SIGTERM it kills all child's PID (first with SIGTERM and then with SIGKILL) and exits 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. π«‘
πΈ ISSUE ESCAPES πΈ
okay bestie listen UP because this is the cute part π ngetty-helper recognizes these escape sequences, and you can sneak them into login-prompt=, newline=, clear=, or straight up in your /etc/issue file:
\dβ drops in the current day (localtime) π\lβ drops in the line that ngetty is running on\mβ drops in the machine architecture (uname -m) π§\nβ drops in the machine's network node hostname (uname -n) π\oβ drops in the domain name\rβ drops in the operating system release (uname -r)\tβ drops in the current time (localtime) β°\sβ drops in the operating system name\uβ drops in the number of users currently logged in π₯\Uβ drops in the string"1 user"or"<n> users", where<n>is the number of users currently logged in\vβ drops in the operating system version (uname -v)\XYZβ drops in a letter with octal codeXYZ
β¨ EXAMPLE β¨
like, for real, this string:
Linux eos i386 #1 Tue Mar 19 21:54:09 MET 1996
was produced by putting "\s \n \m \v" into /etc/issue. iconic behaviour honestly π
π NGETTY-ARGV π
ngetty-argv(8) splits argv[1] on strings, expands %U and %T into username and tty, and then starts the application. the very first char after login-argv= is the split char, periodt. so in the examples above, every user logs on tty4 with no password, and tty5 is always root π
wanna actually get how ngetty-argv works? try this as a non-root bestie:
ngetty-argv ':/bin/echo:echo:%U: on %T' usr tty3
ngetty-argv ':/bin/sleep:-hacker:39:I am %U on %T' 123 X
and you can also yeet options for ngetty-argv at the very beginning:
--β last option-u503β setuid to503-g230β setgid to230-a120βexec alarm(120)before starting the child-s10β sleep10secs before starting the child-d/X/YZβchdir(/X/YZ)before starting the child-r/A/BCβchroot(/A/BC)before starting the child-Dβ start the child in background and exit-N-Cβ NOTTY | SCTTY controlling tty-Sβ likesetsid(8)-e,HOME=/,TERM=linuxβ same asenviron=above-p/path/to/pid.fileβ write the child pid here
one possible example for /etc/ngetty/Conf is:
tty9=clear=
tty9=issue-file=
tty9=login-prompt=\n \d \t qmail-qread:
tty9=login-prog=/usr/sbin/ngetty-argv
tty9=login-argv=:-u106:-g503:-d/var/qmail:--
:./bin/qmail-qread:qread
another example is setting the TTY environ automatically, no cap:
=login-prog=/usr/sbin/ngetty-argv
=login-argv=:-e,TTY=/dev/%T,TERM=linux:--
:/bin/login:login-%T:--:%U
ngl I recommend using ngetty-argv in /etc/inittab too. put as last argument the runlevel string, and then ps will show ngetty-2345 instead of just ngetty π next, start tty1 β¦ tty6 on runlevels 2345:
ng:2345:respawn:/usr/sbin/ngetty-argv
.-e.-S.-d/.-s1.--./usr/sbin/%U.%U-%T.1.2.3.4.5.6
ngetty 2345
and on a terminal (in scripts) start ngetty with:
ngetty-argv .-N.-S.-e./usr/sbin/%U.%U.8.9.10 ngetty
ngetty-argv .-D.-S.-e./usr/sbin/%U.%U.8.9.10 ngetty
fr fr, 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's like a filter between ngetty-helper and the login application. you can easily modify it without touching ngetty-helper. it's similar to DJB's well known argv0(1) and setuidgid(8). you can write your own such programs and use them instead of ngetty-argv β main character energy π
π¦ FILES π¦
/etc/ngetty/Confβ ngetty-helper configuration file/etc/ngetty/Conf.sedβ private setup file/etc/ngetty/setupβ updatesConf.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
π SEE ALSO π
getty(8) fgetty(8) mingetty(8) login(1) nlogin(1) argv0(1) setuidgid(8) stty(1) http://sites.google.com/site/anbadeol/logind
π AUTHOR π
Nikola Vladov http://riemann.fmi.uni-sofia.bg/ngetty/
π COPYRIGHT π
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.
aaaand that's the whole thing bestie, you ate that π
β¨ this page is from NGETTY(8), dated May 2010 β go forth and run your getty with confidence, ily π«Άπ
π¦ where this page comes from
- debian trixie: ngetty 1.1-13 Β· GPL-2.0-or-later
- ubuntu noble: ngetty 1.1-12 Β· GPL-2.0-or-later
- ubuntu questing: ngetty 1.1-13
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms