What is ttys?

"ttys" stands for "TeleTYpewriterS," which is a term used in UNIX and UNIX-like operating systems to refer to terminal devices. Historically, a teletypewriter was an electromechanical device that could send and receive typed messages over a communication line. In the context of modern computing, however, a "tty" refers to a terminal interface that facilitates user interaction with the system through a command-line interface (CLI).

Here’s some key information about ttys:

  1. Physical and Virtual: Originally, a tty represented a physical device connected to the computer, like a keyboard and monitor. Today, it can also refer to virtual terminals, which are software interfaces that emulate the functionality of a physical tty.

  2. Sessions and Shells: When you log into a UNIX-like system via a text-mode interface or open a terminal emulator in a graphical environment, you're assigned a tty session. Each session usually starts with a shell (like bash or zsh) to interact with the system.

  3. Device Files: In UNIX systems, ttys correspond to device files located in the /dev directory. Common file names include /dev/tty, /dev/tty1, /dev/tty2, etc., where each number corresponds to a different terminal session.

  4. Redirecting Input and Output: The concept of ttys is also related to input and output redirection. For processes running in a terminal, stdin, stdout, and stderr are typically directed to the tty. This allows users to interact with the processes via typing and reading outputs on the screen.

  5. TTY Commands: Various commands and programs interact with ttys, including:

    • tty: Displays the file name of the terminal connected to standard input.
    • stty: Used to change and print terminal line settings.
    • w or who: Show who is logged on and what they are doing, often listing active tty sessions.
  6. Virtual Consoles: On many UNIX-like systems, multiple ttys can be accessed simultaneously through different virtual consoles. Users can switch between them using keyboard shortcuts (e.g., Ctrl+Alt+F1, Ctrl+Alt+F2, etc., on Linux systems).

  7. Security: Managing tty access is essential for system security. Unauthorized access to a tty can lead to unauthorized control over a system. Root access over a tty is generally restricted and carefully monitored.

Overall, ttys are fundamental to UNIX-like operating systems, acting as interfaces for user interaction and process management. They’ve evolved from hardware devices to virtual concepts integral to modern computing environments.