When you are managing a headless Linux server via SSH, or interacting with legacy serial hardware (like a router console cable or a massive industrial machine), the terminal interface acts as the bridge between your keyboard and the operating system. Occasionally, a crashing script or a bad serial connection will completely corrupt this bridge, causing your terminal to stop printing characters you type, or causing the Enter key to output bizarre symbols. To inspect, manage, and instantly repair your terminal interface settings, you must use the stty (Set Teletype) command.
How to View Current Terminal Settings
The stty command interacts directly with the Linux kernel’s terminal line discipline (the software layer that handles input and output). To view a highly condensed summary of your current terminal settings, simply run the command without any flags:
stty
This will display the active baud rate (the speed of the connection, usually 38400 for modern pseudo-terminals) and any customized behavioral settings. To force the command to print every single setting it tracks, use the -a (all) flag:
stty -a
The terminal will output a dense block of parameters. You will see flags like echo (which controls whether characters you type physically appear on the screen) and icrnl (which translates a carriage return into a standard newline). If a setting has a minus sign in front of it (e.g., -echo), it means that specific feature is currently disabled.
How to Fix a Corrupted Terminal (The Sane Reset)
If you run a binary file by mistake, or a script crashes violently, it can leave the terminal in a broken state where the echo setting is disabled. You might type commands, but the screen remains completely blank, leading you to believe the server is frozen.
You can instantly reset the terminal to a completely normal, default state by passing the sane argument. Even if you cannot see the letters appearing on your screen, blindly type the following command and press Enter:
stty sane
The kernel will instantly wipe away any custom configurations, re-enable standard typing echo, fix broken newline formatting, and restore your terminal to a perfectly usable condition.
How to Change Baud Rates for Serial Connections
If you are using a physical USB-to-Serial cable to configure a Cisco router or an Arduino microcontroller, the hardware will only communicate if the terminal speed (baud rate) perfectly matches the device.
If you need to forcefully set your active terminal session to communicate at 115200 baud, you simply pass the raw number to the command:
stty 115200
This instantly reconfigures the low-level hardware connection, allowing you to establish a stable communication link with the legacy serial device.