LinuxCommandLibrary

agetty

Open a TTY port for login

TLDR

Connect stdin to a port (relative to /dev) and optionally specify a baud rate (defaults to 9600)

$ agetty [tty] [115200]
copy

Assume stdin is already connected to a tty and set a timeout for the login
$ agetty [[-t|--timeout]] [timeout_in_seconds] -
copy

Assume the tty is 8-bit, overriding the TERM environment variable set by init
$ agetty [[-8|--8bits]] - [term_var]
copy

Skip the login (no login) and invoke, as root, another login program instead of /bin/login
$ agetty [[-n|--skip-login]] [[-l|--login-program]] [login_program] [tty]
copy

Do not display the pre-login (issue) file (/etc/issue by default) before writing the login prompt
$ agetty [[-i|--noissue]] -
copy

Change the root directory and write a specific fake host into the utmp file
$ agetty [[-r|--chroot]] /[path/to/root_directory] [[-H|--host]] [fake_host] -
copy

SYNOPSIS

agetty [options] port baud_rate [termtype]

PARAMETERS

port
    The path to the TTY device file (e.g., ttyS0 for a serial port or tty1 for a virtual console), usually relative to /dev/.

baud_rate
    The initial baud rate or a comma-separated list of baud rates (e.g., 9600,19200,38400) that agetty should attempt to use. A value of 0 signifies autobauding across all common rates.

[termtype]
    An optional argument specifying the terminal type to be set for the connection (e.g., vt100, linux). Defaults to vt100 if not specified.

-h, --flow-control
    Enables hardware (RTS/CTS) flow control on the specified TTY port, essential for reliable serial communication.

-L, --local-enable
    Sets the CLOCAL flag for the tty, indicating a local connection that doesn't use modem control lines, preventing the system from waiting for a carrier detect signal.

-t, --timeout <seconds>
    Specifies a timeout in seconds. If no login name is entered within this period, agetty exits, effectively closing the connection.

-a, --autologin <user>
    Automatically logs in the specified user without prompting for a login name. This is often used for dedicated console access or embedded systems.

-n, --skip-login
    Does not prompt for a login name; instead, it immediately invokes the login program, expecting login itself to handle user identification.

-i, --noissue
    Suppresses the display of the system welcome message from /etc/issue before the login prompt.

-I, --init-string <string>
    Sends an initial string to the TTY device immediately after opening it. Useful for sending AT commands to modems or initializing specific terminal features.

DESCRIPTION

agetty is an alternative to the traditional getty program, primarily used to set up terminal lines for user login. Its standout feature is 'autobauding,' which means it can automatically detect the baud rate of an incoming connection, making it highly useful for serial console connections, modems, and other variable-speed serial devices.

When invoked, agetty opens a specified TTY (Teletypewriter) port, initializes its settings (like baud rate, character processing, flow control), displays the contents of /etc/issue (the system welcome message), and then prompts the user for a login name. Once a login name is entered, agetty typically invokes the /bin/login command, passing the entered username to it. The login program then handles password verification and sets up the user's session.

Unlike getty, which usually requires a fixed baud rate to be specified, agetty can cycle through a list of common baud rates until it detects a valid input, simplifying configuration for diverse serial connections. It is commonly started by init (on older systems) or more frequently by systemd (via getty@.service or serial-getty@.service unit files) to manage login prompts on virtual consoles and serial ports.

CAVEATS

agetty is primarily designed for serial line login and virtual consoles. While it can be used on any TTY, its autobauding feature is most relevant for serial connections. Permissions on the TTY device file are critical; agetty must have appropriate read/write access. Misconfiguration of baud rates or flow control can lead to garbled output or unresponsive terminals.

INTEGRATION WITH SYSTEMD

On modern Linux systems using systemd, agetty is usually invoked by systemd's getty@.service (for virtual consoles) or serial-getty@.service (for serial ports) unit templates. These unit files automate the process of starting agetty on specified TTYs, managing their lifecycle, and ensuring proper terminal setup for login sessions. The systemd-getty-generator is responsible for creating these service units dynamically based on system configuration.

THE <I>/ETC/ISSUE</I> FILE

Before presenting the login prompt, agetty reads and displays the contents of the /etc/issue file. This file typically contains a short system description, warning messages, or legal disclaimers. Administrators can customize this file to provide information or warnings to users before they log in. The --noissue option can be used to prevent this display.

HISTORY

agetty was developed as an improved alternative to the traditional getty utility, specifically addressing the need for automatic baud rate detection on serial lines. This capability was crucial for systems connecting to a variety of serial devices, such as modems with unknown or changing speeds, and for providing a more robust serial console experience. It became part of the widely used util-linux package, ensuring its presence across many Linux distributions. Its role has adapted over time, particularly with the shift from traditional SysVinit to systemd, which now typically manages agetty instances.

SEE ALSO

getty(8), login(1), init(8), systemd-getty-generator(8), systemd-logind(8), tty(4)

Copied to clipboard