Introduction
In this lab, we will explore the Linux getty command, which is a crucial utility for managing virtual terminals and allowing users to log in to the system. We will start by understanding the purpose of the getty command, which is responsible for initializing and configuring virtual terminals, prompting users for their login credentials, and launching the login process after successful authentication. We will then explore the different options available for the getty command and learn how to configure and manage virtual terminals using this tool.
Understand the Purpose of the getty Command
In this step, we will explore the purpose of the getty command in Linux. The getty command is a crucial utility that manages virtual terminals, allowing users to log in to the system.
The getty command is responsible for:
- Initializing and configuring virtual terminals
- Prompting users for their login credentials
- Launching the login process after successful authentication
Let's start by understanding the basic usage of the getty command:
sudo getty --help
Example output:
Usage: getty [options] <line>
-L, --local-line Use local line discipline
-m, --issue-motd Print /etc/issue before login
-n, --skip-login Don't prompt for login
-t, --timeout TIMEOUT Terminate if no login in TIMEOUT seconds
-I, --init-string INIT Set init string
-w, --wait-cr Wait for carriage return before sending init
-i, --flow-control Use input flow control
-8, --8bits Pass 8-bit input to program
-2, --2-stop Use 2 stop bits
--noclear Do not clear the screen
--nohints Do not print login hints
--nohostname Do not print hostname
--noreset Do not reset control mode
--nohints-reset Do not reset control mode for hints
--nohints-timeout Do not reset control mode for hints timeout
--nonewline Do not send a newline
--noissue Do not print /etc/issue
--nohost Do not print hostname
--notruncate Do not truncate username
--noflow-control Do not use input flow control
--nohostname-check Do not check for valid hostname
--noparity Disable parity checking
--nohostname-check-dns Do not check hostname against DNS
--nologin-timeout Disable login timeout
--nologin-timeout-signal Disable login timeout signal
--nologin-timeout-action Disable login timeout action
--nologin-timeout-message Disable login timeout message
--nologin-timeout-warning Disable login timeout warning
--nologin-timeout-warning-message Disable login timeout warning message
--help Display this help and exit
--version Output version information and exit
The getty command is typically used in the system initialization process to set up and manage virtual terminals. It is responsible for prompting the user for their login credentials and launching the login process.
In the next step, we will explore the different options available with the getty command and learn how to configure and manage virtual terminals using it.
Explore the Different getty Command Options
In this step, we will explore the different options available with the getty command and learn how to configure and manage virtual terminals using it.
Let's start by looking at some of the commonly used getty command options:
sudo getty -m -n -t 60 tty1
This command will:
-m: Print the/etc/issuemessage of the day before the login prompt-n: Skip the login prompt and directly launch the login process-t 60: Set the login timeout to 60 seconds
Example output:
Linux ubuntu 5.15.0-1023-aws #25~20.04.1-Ubuntu SMP Fri Sep 30 12:36:29 UTC 2022 x86_64
ubuntu login:
Another useful option is --flow-control, which enables input flow control for the terminal:
sudo getty --flow-control tty2
This will start a new virtual terminal on tty2 with input flow control enabled.
You can also set the initial string to be sent to the terminal using the -I option:
sudo getty -I "Welcome to the Lab!" tty3
This will start a new virtual terminal on tty3 and display the "Welcome to the Lab!" message before the login prompt.
In the next step, we will learn how to configure and manage virtual terminals using the getty command.
Configure and Manage Virtual Terminals using getty
In this final step, we will learn how to configure and manage virtual terminals using the getty command.
First, let's create a new virtual terminal:
sudo getty tty4
This will start a new virtual terminal on tty4. You can switch to this terminal by pressing Ctrl+Alt+F4.
To configure the virtual terminal, we can use the getty command with various options. For example, to set the login timeout to 120 seconds:
sudo getty -t 120 tty4
You can also set the initial string to be displayed before the login prompt:
sudo getty -I "Welcome to the Virtual Terminal!" tty4
To stop a virtual terminal, you can use the kill command:
sudo kill $(ps -ef | grep getty | grep tty4 | awk '{print $2}')
This will stop the getty process running on the tty4 virtual terminal.
Finally, let's create a script to automatically start and configure multiple virtual terminals:
#!/bin/bash
## Start virtual terminals
sudo getty tty4 &
sudo getty -t 60 tty5 &
sudo getty -I "Virtual Terminal 6" tty6 &
## Wait for the terminals to be ready
sleep 5
## Switch to the first virtual terminal
sudo chvt 4
Save this script as start_terminals.sh in your ~/project directory and make it executable:
chmod +x ~/project/start_terminals.sh
Now, you can run the script to start the virtual terminals:
~/project/start_terminals.sh
You can switch between the virtual terminals using the Ctrl+Alt+F4, Ctrl+Alt+F5, and Ctrl+Alt+F6 key combinations.
Summary
In this lab, we explored the purpose and usage of the getty command in Linux. The getty command is responsible for initializing and configuring virtual terminals, prompting users for their login credentials, and launching the login process after successful authentication. We learned about the various options available with the getty command, such as setting the initialization string, enabling input flow control, and configuring the login timeout. Additionally, we discussed how to configure and manage virtual terminals using the getty command.



