Getty: Difference between revisions

From ArchWiki
m (→‎Virtual console: not a big deal, it does not damage anything (see Help:Style#Notes, Warnings, Tips))
(simplification and beautification of wikilinks (interactive))
 
(52 intermediate revisions by 21 users not shown)
Line 2: Line 2:
[[Category:Boot process]]
[[Category:Boot process]]
[[Category:Linux console]]
[[Category:Linux console]]
[[es:Getty]]
[[fr:Getty]]
[[ja:Getty]]
[[ja:Getty]]
[[pt:Getty]]
[[ru:Getty]]
[[zh-hans:Getty]]
[[zh-hans:Getty]]
{{Related articles start}}
{{Related articles start}}
{{Related|Display manager}}
{{Related|Display manager}}
{{Related articles end}}
{{Related articles end}}
A [[w:getty (Unix)|getty]] is the generic name for a program which manages a terminal line and its connected terminal.  Its purpose is to protect the system from unauthorized access.  Generally, each getty process is started by [[systemd]] and manages a single terminal line.  
A [[w:getty (Unix)|getty]] is the generic name for a program which manages a terminal line and its connected terminal.  Its purpose is to protect the system from unauthorized access.  Generally, each getty process is started by [[systemd]] and manages a single terminal line.


== Installation ==
== Installation ==


{{Style|Description of TTY settings and "staircase effect" is out of context here. The default number of TTYs can be moved to [[#Add additional virtual consoles]] as it does not depend on agetty.}}
''agetty'' is the default getty in Arch Linux, as part of the {{Pkg|util-linux}} package.
 
''agetty'' is the default getty in Arch Linux, as part of the {{Pkg|util-linux}} package. It modifies the TTY settings while waiting for a login so that the newlines are not translated to CR-LFs. This tends to cause a "staircase effect" for messages printed to the console. Agetty manages virtual consoles and six of these virtual consoles are provided by default in Arch Linux. They are usually accessible by pressing {{ic|Ctrl+Alt+F1}} through {{ic|Ctrl+Alt+F6}}.


Alternatives include:
Alternatives include:


* {{App|mingetty|A minimal getty which allows automatic logins.|{{AUR|mingetty}}|{{AUR|mingetty}}}}
* {{App|mingetty|A minimal getty which allows automatic logins.|{{AUR|mingetty}}|{{AUR|mingetty}}}}
* {{App|fbgetty|A console getty like mingetty, which supports framebuffers.|http://projects.meuh.org/fbgetty/|{{AUR|fbgetty}}}}
* {{App|mgetty|A versatile program to handle all aspects of a modem under Unix.|http://mgetty.greenie.net/|{{AUR|mgetty}}}}
* {{App|mgetty|A versatile program to handle all aspects of a modem under Unix.|http://mgetty.greenie.net/|{{AUR|mgetty}}}}


== Add additional virtual consoles ==
== Tips and tricks ==
 
=== Staircase effect ===
 
''agetty'' modifies the TTY settings while waiting for a login so that the newlines are not translated to CR-LFs. This tends to cause a "staircase effect" for messages printed to the console.
 
It is entirely harmless, but in the event it persists once logged, you can fix this behavior with:


Open the file {{ic|/etc/systemd/logind.conf}} and set the option '''NAutoVTs=6''' to the number of virtual terminals that you want at boot.
$ stty onlcr


If you wish to start one temporarily, you can start a getty service at the desired TTY by typing:
See this [https://bbs.archlinux.org/viewtopic.php?id=264094 forums discussion] on the subject.


$ systemctl start getty@ttyN.service
=== Add additional virtual consoles ===


== Automatic login to virtual console ==
Agetty manages virtual consoles and six of these virtual consoles are provided by default in Arch Linux. They are usually accessible by pressing {{ic|Ctrl+Alt+F1}} through {{ic|Ctrl+Alt+F6}}.


Configuration relies on systemd [[Systemd#Editing provided units|drop-in files]] to override the default parameters passed to ''agetty''.
Open the file {{ic|/etc/systemd/logind.conf}} and set the option {{ic|1=NAutoVTs=6}} to the number of virtual terminals that you want at boot.
 
If needed, it is possible to temporarily [[start]] a {{ic|getty@tty''N''.service}} service directly.
 
=== Automatic login to virtual console ===
 
Configuration relies on systemd unit [[drop-in file]]s to override the default parameters passed to ''agetty''.


Configuration differs for virtual versus serial consoles. In most cases, you want to set up automatic login on a virtual console, (whose device name is {{ic|tty''N''}}, where {{ic|''N''}} is a number). The configuration of automatic login for serial consoles will be slightly different. Device names of the serial consoles look like {{ic|ttyS''N''}}, where {{ic|''N''}} is a number.
Configuration differs for virtual versus serial consoles. In most cases, you want to set up automatic login on a virtual console, (whose device name is {{ic|tty''N''}}, where {{ic|''N''}} is a number). The configuration of automatic login for serial consoles will be slightly different. Device names of the serial consoles look like {{ic|ttyS''N''}}, where {{ic|''N''}} is a number.


=== Virtual console ===
{{Tip|Consider using [[greetd]]'s auto-login feature. It will not auto-login a second time if the initial session exits, but will show a login screen instead.}}


{{Note|1=[https://bbs.archlinux.org/viewtopic.php?id=238576 It has been reported] that this method may interfere with the hibernating process.}}
==== Virtual console ====


[[systemd#Editing provided units|Edit the provided unit]] either manually by creating the following drop-in snippet, or by running {{ic|systemctl edit getty@tty1}} and pasting its content:
Create a [[drop-in file]] for {{ic|getty@tty1.service}} with the following contents:


{{hc|/etc/systemd/system/getty@tty1.service.d/override.conf|2=
{{hc|/etc/systemd/system/getty@tty1.service.d/autologin.conf|2=
[Service]
[Service]
ExecStart=
ExecStart=
ExecStart=-/usr/bin/agetty --autologin ''username'' --noclear %I $TERM
ExecStart=-/sbin/agetty -o '-p -f -- \\u' --noclear --autologin ''username'' %I $TERM
}}
}}


{{Tip|The option {{ic|1=Type=idle}} found in the default {{ic|getty@.service}} will delay the service startup until all jobs (state change requests to units) are completed in order to avoid polluting the login prompt with boot-up messages. When [[Start X at login|starting X automatically]], it may be useful to start {{ic|getty@tty1.service}} immediately by adding {{ic|1=Type=simple}} into the [[drop-in snippet]]. Both the init system and ''startx'' can be [[Silent boot|silenced]] to avoid the interleaving of their messages during boot-up.}}
{{Tip|
* The option {{ic|1=Type=idle}} found in the default {{ic|getty@.service}} will delay the service startup until all jobs (state change requests to units) are completed in order to avoid polluting the login prompt with boot-up messages. When [[Start X at login|starting X automatically]], it may be useful to start {{ic|getty@tty1.service}} immediately by adding {{ic|1=Type=simple}} into the drop-in file. Both the init system and ''startx'' can be [[Silent boot|silenced]] to avoid the interleaving of their messages during boot-up.
* See [[Silent boot#agetty]] for an example virtual console drop-in file which hides the login prompt completely.
* The above snippet will cause the loginctl session type to be set to {{ic|tty}}. If desirable (for example if [[Start X at login|starting X automatically]]), it is possible to manually set the session type to {{ic|wayland}} or {{ic|x11}} by adding {{ic|1=Environment=XDG_SESSION_TYPE=x11}} or {{ic|1=Environment=XDG_SESSION_TYPE=wayland}} into this file.
}}


If you want to use a ''tty'' other than ''tty1'', see [[Systemd FAQ#How_do_I_change_the_default_number_of_gettys.3F|systemd FAQ]].
If you do not want full automatic login, but also do not want to type your username, see [[#Prompt only the password for a default user in virtual console login]].


=== Serial console ===
If you want to use a ''tty'' other than ''tty1'', see [[systemd/FAQ#How do I change the default number of gettys?]].


Create the following file (and leading directories):
==== Serial console ====
 
Create a [[drop-in file]]:


{{hc|/etc/systemd/system/serial-getty@ttyS0.service.d/autologin.conf|2=
{{hc|/etc/systemd/system/serial-getty@ttyS0.service.d/autologin.conf|2=
[Service]
[Service]
ExecStart=
ExecStart=
ExecStart=-/usr/bin/agetty --autologin ''username'' -s %I 115200,38400,9600 vt102
ExecStart=-/sbin/agetty -o '-p -f -- \\u' --keep-baud --autologin ''username'' 115200,57600,38400,9600 - $TERM
}}
 
==== Nspawn console ====
 
To configure auto-login for a [[systemd-nspawn]] container, override {{ic|console-getty.service}} by creating a [[drop-in file]]:
 
{{hc|/etc/systemd/system/console-getty.service.d/autologin.conf|2=
[Service]
ExecStart=
ExecStart=-/sbin/agetty -o '-p -f -- \\u' --noclear --keep-baud --autologin ''username'' - 115200,38400,9600 $TERM
}}
}}


=== Nspawn console ===
If {{ic|machinectl login ''my-container''}} method is used to access the container, also adjust the {{ic|container-getty@.service}} template that manages {{ic|pts/[0-9]}} pseudo ttys:


To configure auto-login for a [[systemd-nspawn]] container, override ''console-getty'' service:
{{hc|/etc/systemd/system/container-getty@.service.d/autologin.conf|2=
[Service]
ExecStart=
ExecStart=-/sbin/agetty -o '-p -f -- \\u' --noclear --keep-baud --autologin ''username'' - 115200,38400,9600 $TERM
}}


{{hc|/etc/systemd/system/console-getty.service.d/override.conf|2=
=== Prompt only the password for a default user in virtual console login ===
 
Getty can be used to login from a virtual console with a default user, typing the password but without needing to insert the username. For instance, to prompt the password for {{ic|''username''}} on {{ic|tty1}}:
 
{{hc|/etc/systemd/system/getty@tty1.service.d/skip-username.conf|2=
[Service]
[Service]
ExecStart=
ExecStart=
ExecStart=-/sbin/agetty --noclear --autologin ''username'' --keep-baud console 115200,38400,9600 $TERM
ExecStart=-/sbin/agetty -o '-p -- ''username''<nowiki/>' --noclear --skip-login - $TERM
}}
}}


== Have boot messages stay on tty1 ==
and then [[enable]] {{ic|getty@tty1}}.


By default, Arch has the {{ic|getty@tty1}} service enabled. The service file already passes {{ic|--noclear}}, which stops agetty from clearing the screen. However [[systemd]] clears the screen before starting it. To disable this behavior, create {{ic|/etc/systemd/system/getty@tty1.service.d/noclear.conf}}:
=== Have boot messages stay on tty1 ===
 
By default, Arch has the {{ic|getty@tty1}} service enabled. The service file already passes {{ic|--noclear}}, which stops agetty from clearing the screen. However [[systemd]] clears the screen before starting it. To disable this behavior, create a [[drop-in file]]:


{{hc|1=/etc/systemd/system/getty@tty1.service.d/noclear.conf|2=
{{hc|1=/etc/systemd/system/getty@tty1.service.d/noclear.conf|2=
Line 79: Line 118:
TTYVTDisallocate=no
TTYVTDisallocate=no
}}
}}
This overrides only {{ic|TTYVTDisallocate}} for ''agetty'' on TTY1, and leaves the global service file {{ic|/usr/lib/systemd/system/getty@.service}} untouched. See [[Systemd#Editing provided units]].


{{Note|
{{Note|
* Make sure to remove {{ic|quiet}} from the [[kernel parameter]]s.
* Make sure to remove {{ic|quiet}} from the [[kernel parameter]]s.
* Late KMS starting may cause the first few boot messages to clear. See [[KMS#Early KMS start]] or [[KMS#Disabling modesetting]].
* Late KMS starting may cause the first few boot messages to clear. See [[NVIDIA#Early loading]].
}}
}}


== See also ==
== See also ==


* [[Systemd#Change default target to boot into]]
* [[systemd#Change default target to boot into]]
* [http://www.linusakesson.net/programming/tty/ The TTY demystified]
* [https://www.linusakesson.net/programming/tty/ The TTY demystified]
* [[Wikipedia:Tty (unix)]]
* [[Wikipedia:tty (unix)]]

Latest revision as of 20:57, 20 May 2023

A getty is the generic name for a program which manages a terminal line and its connected terminal. Its purpose is to protect the system from unauthorized access. Generally, each getty process is started by systemd and manages a single terminal line.

Installation

agetty is the default getty in Arch Linux, as part of the util-linux package.

Alternatives include:

  • mingetty — A minimal getty which allows automatic logins.
mingettyAUR || mingettyAUR
  • mgetty — A versatile program to handle all aspects of a modem under Unix.
http://mgetty.greenie.net/ || mgettyAUR

Tips and tricks

Staircase effect

agetty modifies the TTY settings while waiting for a login so that the newlines are not translated to CR-LFs. This tends to cause a "staircase effect" for messages printed to the console.

It is entirely harmless, but in the event it persists once logged, you can fix this behavior with:

$ stty onlcr

See this forums discussion on the subject.

Add additional virtual consoles

Agetty manages virtual consoles and six of these virtual consoles are provided by default in Arch Linux. They are usually accessible by pressing Ctrl+Alt+F1 through Ctrl+Alt+F6.

Open the file /etc/systemd/logind.conf and set the option NAutoVTs=6 to the number of virtual terminals that you want at boot.

If needed, it is possible to temporarily start a getty@ttyN.service service directly.

Automatic login to virtual console

Configuration relies on systemd unit drop-in files to override the default parameters passed to agetty.

Configuration differs for virtual versus serial consoles. In most cases, you want to set up automatic login on a virtual console, (whose device name is ttyN, where N is a number). The configuration of automatic login for serial consoles will be slightly different. Device names of the serial consoles look like ttySN, where N is a number.

Tip: Consider using greetd's auto-login feature. It will not auto-login a second time if the initial session exits, but will show a login screen instead.

Virtual console

Create a drop-in file for getty@tty1.service with the following contents:

/etc/systemd/system/getty@tty1.service.d/autologin.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty -o '-p -f -- \\u' --noclear --autologin username %I $TERM
Tip:
  • The option Type=idle found in the default getty@.service will delay the service startup until all jobs (state change requests to units) are completed in order to avoid polluting the login prompt with boot-up messages. When starting X automatically, it may be useful to start getty@tty1.service immediately by adding Type=simple into the drop-in file. Both the init system and startx can be silenced to avoid the interleaving of their messages during boot-up.
  • See Silent boot#agetty for an example virtual console drop-in file which hides the login prompt completely.
  • The above snippet will cause the loginctl session type to be set to tty. If desirable (for example if starting X automatically), it is possible to manually set the session type to wayland or x11 by adding Environment=XDG_SESSION_TYPE=x11 or Environment=XDG_SESSION_TYPE=wayland into this file.

If you do not want full automatic login, but also do not want to type your username, see #Prompt only the password for a default user in virtual console login.

If you want to use a tty other than tty1, see systemd/FAQ#How do I change the default number of gettys?.

Serial console

Create a drop-in file:

/etc/systemd/system/serial-getty@ttyS0.service.d/autologin.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty -o '-p -f -- \\u' --keep-baud --autologin username 115200,57600,38400,9600 - $TERM

Nspawn console

To configure auto-login for a systemd-nspawn container, override console-getty.service by creating a drop-in file:

/etc/systemd/system/console-getty.service.d/autologin.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty -o '-p -f -- \\u' --noclear --keep-baud --autologin username - 115200,38400,9600 $TERM

If machinectl login my-container method is used to access the container, also adjust the container-getty@.service template that manages pts/[0-9] pseudo ttys:

/etc/systemd/system/container-getty@.service.d/autologin.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty -o '-p -f -- \\u' --noclear --keep-baud --autologin username - 115200,38400,9600 $TERM

Prompt only the password for a default user in virtual console login

Getty can be used to login from a virtual console with a default user, typing the password but without needing to insert the username. For instance, to prompt the password for username on tty1:

/etc/systemd/system/getty@tty1.service.d/skip-username.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty -o '-p -- username' --noclear --skip-login - $TERM

and then enable getty@tty1.

Have boot messages stay on tty1

By default, Arch has the getty@tty1 service enabled. The service file already passes --noclear, which stops agetty from clearing the screen. However systemd clears the screen before starting it. To disable this behavior, create a drop-in file:

/etc/systemd/system/getty@tty1.service.d/noclear.conf
[Service]
TTYVTDisallocate=no
Note:

See also