File: ngetty.8

package info (click to toggle)
ngetty 0.4-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 300 kB
  • ctags: 202
  • sloc: ansic: 1,464; makefile: 230; sh: 109; asm: 100
file content (642 lines) | stat: -rw-r--r-- 14,335 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
.TH NGETTY 8 "April 2008"
.
.SH NAME
.
.BR ngetty 
\- daemon for virtual console terminals
.
.SH SYNOPSIS
.BR ngetty 
[ tty1 | vc/1 | 1 ] [ /dev/tty2 | vc/2 | 2 ] ...
.br
.BR ngetty-helper
/dev/ttyX [ login ]
.br
.BR ngetty-argv
:options:child:name:args username tty

.
.SH DESCRIPTION
.
.B ngetty
is a daemon that starts login sessions on virtual console terminals,
on demand.  It opens the virtual console terminals specified by the
.I tty...
arguments, displays a
.IR /etc/issue 
message, 
prints the login prompt 
on each terminal
and waits for user name.
On user action,
.B ngetty
executes
.BR login (1)
in a new process with the terminal the user is typing in as the
controlling terminal.
.PP
.BR login (1)
then prompts for a password to login with the system and
finally, if the login succeeds, executes the user's login shell.
.PP
When the user logs out,
.B ngetty
restarts the corresponding virtual console terminal.
.PP
.PP
Actually almost the whole work is done by a 
.B ngetty-helper
program.
It makes 
.IR /var/run/utmp ,
.IR /var/log/wtmp
records, prints 
.IR /etc/issue , 
hostname, login prompt,
waits for user name.
.B ngetty 
invokes the 
.B ngetty-helper 
by need.
.
.SH HISTORY
.
The traditional way to enable logins on virtual console terminals is
to start a bunch of
.BR getty (8)
programs, one for each virtual console terminal, from
.BR init (8).
As most users rarely login on virtual console terminals nowadays, preferring
graphical logins instead, it seems wasteful to have all those
.BR getty (8)
processes doing nothing but wasting memory.
Alternatively,
.B ngetty
manages logins on any number of virtual console terminals from a single,
light, process.
.
.SH INVOCATION
.
.B ngetty
does not use stdin, stdout or stderr and closes them.
.PP
When running
.B 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.:
.PP
.RS
setsid ngetty tty...  &
.RE
.PP
To start
.B ngetty
from
.BR init (8),
add something like this to
.IR /etc/inittab :
.PP
.RS
ng:2345:respawn:/sbin/ngetty tty1 tty2 ... tty6 
.RE
.PP
If 
.B ngetty-argv
is available use it to start ngetty from
.IR /etc/inittab .
See the example bellow.
.
.SH DIAGNOSTICS
.
If
.B ngetty
can not open one of the virtual console terminals specified in the
.I tty...
arguments, most likely because that
.I tty
device node does not exist, no greeting message will be displayed on
that terminal, obviously, and
.B ngetty
will simply go on, ignoring the offending terminal.
Create the missing 
.I tty 
device and send SIGCHLD to ngetty.
Then it will reopen the new
.IR tty .
Instead of sending SIGCHLD you can login and logout on some 
working
.IR tty .
This also forces ngetty to reopen the new
.IR tty .

.
.PP
.B ngetty 
uses
.B ngetty-helper
program.  
It's path is hard-coded in 
.BR ngetty . 
Never remove 
.B ngetty-helper 
program nor move it to other location.
.PP
If, on user action,
.B ngetty-helper
can not execute
.BR login (1),
in all likelihood because the compiled-in
.B LOGIN
path does not match your system's
.BR login (1)
path,
.B ngetty
restarts the terminal and redisplays the greeting message.
.PP
In any case,
.B ngetty
does not output error messages.
.PP

.SH OPTIONS
It's possible to set different options for 
.B ngetty\-helper 
program in file 
.IR /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:
.PP
.RS
.B # options format:
.br
.B # [ttyX]=option[=value]
.br
.B #=debug
.br
=environ=,TERM=linux
.br
tty3=long-hostname
.br 
tty1=clear=\e033c
.br 
=newline=
.br
=timeout=180
.br
tty1=timeout=60
.br
tty1=delay=1
.RE
.PP
For security reasons
.B ngetty-helper
evaluate the file 
.IR /etc/ngetty/Conf
only if it has mode:
.PP
.RS
-rw-------    root   root   /etc/ngetty/Conf
.RE
.
.PP
.B ngetty-helper 
recognizes the following options which might be embedded in the 
.I /etc/ngetty/Conf
file:
.TP
.B # tty5=login-prog=/bin/login.test
If a line starts with 
.BR # ,
.B space
or 
.B tab
it is a comment.
.TP
.B debug
If debug is set 
.B ngetty-helper
write on terminal 
all successfully applied options.  Set this on the fist line of
.IR /etc/ngetty/Conf  
file.
.TP
.B date-string
Escape
\fB\\d\fP (current day)
in
.IR /etc/issue
as:
.br
\fBFri Jun 01 2007\fP.
Default is: 
\fB2007-06-01\fP.
.TP
.B days=string 
Abbreviation for week days (21 bytes).  Default is:
.br
.B =days=SunMonTueWedThuFriSat
.TP
.B months=string 
Abbreviation for months (36 bytes).  Default is:
.br
.B =months=JanFebMarAprMayJunJulAugSepOctNovDec
.TP
.B tz=string 
Change the timezone offset.  If the string starts
with slash it's the name of tzfile.  
The string is positive number if the local
time zone is east of the Prime Meridian 
and negative if it is west.
Default is 
.IR /etc/localtime .
Examples:
.br
\fB=tz=-18000\fP        -0500
.br
\fB=tz=7200\fP          +0200
.br
\fB=tz=/etc/localtime\fP
.br
\fB=tz=AUTO\fP
.TP
.B echo-off
Turn the echo off just before starting /bin/login.  It's similar
to \fBstty -echo\fP.
.TP
.B newline=string
Print this \fBstring\fP before writing out 
.IR /etc/issue .
(default is \fB\e012\fP).
Example:
.br
.B tty3=newline=\e012I am \el\e012
.TP
.B clear=string
Clear the screen before prompting for the login name with the 
\fBstring\fP (default is \fP\e033c\fP).  Examples:
.br
.B tty1=clear=
.br
.B tty3=clear=\e033[H\e033[J
.TP
.B noclear-first=/etc/ngetty/.noclear
Do not clear the screen before prompting for the login name the
first time after reboot.  Example:
.br
.B tty1=noclear-first=/etc/ngetty/.noclear.tty1
.TP
.B nohangup
Do not call vhangup() to disable writing to this tty by
other applications.
.TP
.B long\-hostname
By default the hostname is only printed until the first dot.
With this option enabled, the full text from gethostname() is shown.
.
.TP
.B nousername
Do not ask for user name.  Exec login(1) immediately.  Example:
.br
.B =nousername
.br
\fB=login-prompt= Press ENTER to activate \el\bP
.
.TP
.B deny=,black,list,users...
Disable login process for some users.  The first char after "deny=" 
is split char.  Example:
.br
.B tty1=deny=,root,nobody,guest
.TP
.B allow=,white,list,users...
Enable login process only for the users.  
The first char after "allow=" is split char.  Example:
.br
.B =clear=
.br
.B =allow=,root,operator
.
.TP
.B print=an:CM:PY:04:69
Accept only these chars in user name.  Default is to
accept only "\fB,-._ 0-9 a-z A-Z\fP".  Examples:
.br
.B tty1=print=az:AZ
.br
.B tty2=print=az:AZ:__:,.:09
.TP
.B issue-file=/etc/issue
Change the issue file.  Disable printing of the issue file with:
.br
.B =issue-file=
.TP
.B login-prog=/bin/login
Change the login app.  It's possible to use fgetty's 
.IR /bin/login1
application with:
.br
.B =echo-off
.br
.B =login-prog=/bin/login1
.
.TP
.B login-prompt=\en login: 
Change the login prompt string.  Example:
.br
\fB=login-prompt=\e033[1;33m\el\e033[0;39m  \en login: \fP
.TP
.B nice=10
Change the priority by calling nice().
.TP
.B delay=5
Sleep this many seconds before printing the file /etc/issue.
.TP
.B timeout=180
Wait at most this many seconds for user name.
.TP
.B chdir=/home
Change into this directory before calling the login prog.
.TP
.B chroot=/chroot
Call chroot() with this directory name.
.TP
.B autologin-name=username
Log the specified user automatically in without asking for
a login name and password.  Check the \-f option from
.B /bin/login 
for this.
Example:
.br
.B tty1=autologin-name=maria
.TP
.B autologin-first=/etc/ngetty/.autologin
Log in automatically only the first time after reboot without asking for
a login name and password. 
Example:
.br
.B tty1=autologin-name=maria
.br
.B tty1=autologin-first=/etc/ngetty/.autologin
.TP
.B environ=,TERM=linux
Replace the environ.  The first char after "environ=" 
is split char.  Examples:
.br
.B =environ=,TERM=vt100,PATH=/bin:/usr/bin,HOME=/
.br
.B tty3=environ=,TERM=linux,TTY=/dev/tty3
.TP
.B sh-A=line
Exec this line before printing
.IR /etc/issue .  
The line is executed using 
.B /bin/sh -c 
.IR line .  
It's good idea
to use the full paths here.  Example:
.br
.B tty4=sh-A=exec /bin/ps e -u root
.br
.B tty4=delay=8
.TP
.B sh-B=line
Similar to option
.B sh-A.  
This is executed before asking for username.
.TP
.B login-argv=any_string
Ngetty starts login application with options
.br
\fBlogin -- XYZ\fP      # default
.br
\fBlogin -f XYZ\fP      # if autologin-name=XYZ
.br
With this option it's possible to start login appl
with \fBany_string\fP instead of \fB\--\fP or \fB-f\fP.
Using the program \fBngetty-argv\fP(8) one can start
arbitrary program with different arguments.  Two very
dangerous examples are (never try them):
.br
.B tty4=login-prog=/sbin/ngetty-argv
.br
.B tty5=login-prog=/sbin/ngetty-argv
.br
.B tty4=login-argv=,/bin/login,login,-f,%U
.br
.B tty5=login-argv=:/bin/bash:-bash
.
.PP
.SH "WARNING"
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.
.PP
Do not edit the file
.IR /etc/ngetty/Conf
directly.
Put the configurations in
.IR /etc/ngetty/Conf.sed
(the same permition as 
.IR /etc/ngetty/Conf )
and after editing it exec:
.PP
.RS
.B cd /etc/ngetty && ./setup
.RE
.PP
The script 
.I /etc/ngetty/setup
removes comments, merges lines ending with backslash and
expand the string \fB=tz=AUTO\fP to numeric number.
It updates then 
.IR /etc/ngetty/Conf .
.PP
.SH "SIGNALS"
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.
.
.PP
.SH "ISSUE ESCAPES"
.B ngetty-helper 
recognizes the following escapes sequences which might be embedded 
after  \fBlogin-prompt=\fP, \fBnewline=\fP, \fBclear=\fP
or in the 
.I /etc/issue
file:
.IP \fB\ed\fP
insert current day (localtime),
.IP \fB\el\fP
insert line on which 
.B ngetty 
is running,
.IP \fB\em\fP
inserts machine architecture (uname -m),
.IP \fB\en\fP
inserts machine's network node hostname (uname -n),
.IP \fB\eo\fP
inserts domain name,
.IP \fB\er\fP
inserts operating system release (uname -r),
.IP \fB\et\fP
insert current time (localtime),
.IP \fB\es\fP
inserts operating system name,
.IP \fB\eu\fP
insert the number of users which are currently logged in,
.IP \fB\eU\fP
insert the  string  "1 user" or "<n> users", where <n> is
the number of users currently logged  in,
.IP \fB\ev\fP
inserts operating system version (uname -v).
.IP \fB\eXYZ\fP
inserts a letter with octal code XYZ.
.PP
.SH EXAMPLE
"\fBLinux\ eos\ i386\ #1\ Tue\ Mar\ 19\ 21:54:09\ MET\ 1996\fP" was produced
by putting "\fB\\s\ \\n\ \\m\ \\v\fP" into
.IR /etc/issue .
.
.PP
.SH "NGETTY-ARGV"
The program \fBngetty-argv\fP(8) splits argv[1] on strings, 
expands \fB%U\fP and \fB%T\fP 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 \fBngetty-argv\fP works try as non-root:
.br
.PP
.B ngetty-argv ':/bin/echo:echo:%U: on %T' usr tty3
.br
.B ngetty-argv ':/bin/sleep:-hacker:39:I am %U on %T' 123 X 
.PP
.TP
One can put also options for ngetty-argv at the beginning.
.IP
\fB--\fP         last option
.IP
\fB-u503\fP      setuid to 503
.IP
\fB-g230\fP      setgid to 230
.IP
.br
\fB-a120\fP      exec alarm(120) before starting child
.IP
\fB-s10\fP       sleep 10 secs before starting child
.IP
\fB-d/X/YZ\fP    chdir(/X/YZ)  before starting child
.IP
\fB-r/A/BC\fP    chroot(/A/BC) before starting child
.IP
\fB-S\fP         like \fBsetsid\fP(8)
.IP
\fB-e,HOME=/,TERM=linux\fP     same as \fBenviron=\fP above
.IP
\fB-p/path/to/pid.file\fP      write the child pid here
.
.PP
One possible example for \fB/etc/ngetty/Conf\fP is:
.RS 4
.br
tty9=clear=
.br
tty9=issue-file=
.br
tty9=login-prompt=\en  \ed \et  qmail-qread: 
.br
tty9=login-prog=/sbin/ngetty-argv
.br
tty9=login-argv=:-u106:-g503:-d/var/qmail:--
.br
  :./bin/qmail-qread:qread
.RE
.PP
Another example is setting the TTY environ automatically:
.RS 4
=login-prog=/sbin/ngetty-argv
.br
=login-argv=:-e,TTY=/dev/%T,TERM=linux:--
.br
  :/bin/login:login-%T:--:%U
.RE
.
.PP
I recommend using \fBngetty-argv \fP in 
.IR /etc/inittab
also.
Put as last argument runlevel string.  Then ps will
show \fBngetty-2345\fP instead of \fBngetty\fP.  Next
start tty1 ... tty6 on runlevels 2345.
.RS 4
ng:\fB2345\fP:respawn:/sbin/ngetty-argv 
.br
  .-e.-S.-d/.-s1.--./sbin/%U.%U-%T.1.2.3.4.5.6 
.br
  ngetty \fB2345\fP
.RE
.
.PP
This program is a hack written for \fBngetty-helper\fP.  
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 \fBargv0\fP(1) and
\fBsetuidgid\fP(8).
You can write own such programs
and use them instead of ngetty-argv.
.
.SH FILES
.TS
tab (@);
l l.
/etc/ngetty/Conf@ \fBngetty-helper\fP configuration file
/etc/ngetty/Conf.sed@ private setup file
/etc/ngetty/setup@ updates \fBConf.sed -> Conf\fP
/etc/issue@ printed before the login prompt
/var/run/utmp@ the system status file
/var/log/wtmp@ the system logging file
/etc/inittab@ \fBinit\fP(8) configuration file
.TE
.
.PP
.SH SEE ALSO
.
.BR getty (8)
.BR fgetty (8)
.BR mingetty (8)
.br
.BR login (1) 
.BR nlogin (1)
.BR argv0 (1)
.BR setuidgid (8)
.br
http://anbadeol.googlepages.com/logind.html
.
.SH AUTHOR
.
Nikola Vladov
.br
http://riemann.fmi.uni-sofia.bg/ngetty/
.
.SH COPYRIGHT
.
Copyright 2007,2008 Nikola Vladov
.PP
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.
.PP
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.