How to Change Terminal Settings Using the stty Command in Linux

If you connect to a Linux server remotely and notice that your terminal is behaving erratically—such as failing to echo the characters you type, misinterpreting the Backspace key, or scrolling text at unreadable speeds—the underlying configuration of your TTY (teletypewriter) session is likely corrupted. To diagnose and forcefully reset these critical communication parameters, you must use the stty (set teletype) command.

How to View Current Terminal Settings

The stty command is designed to query and modify the line discipline characteristics of your current terminal interface.

To view a comprehensive dump of all the active settings for your current session, simply run the command with the -a (all) flag:

stty -a

The terminal will output a dense block of text detailing dozens of configurations. It will display the baud rate (speed), the exact control character mapping (for example, confirming that ^C triggers the interrupt signal), and a massive list of behavioral toggles (like echo, icanon, and isig). If a toggle has a minus sign in front of it (e.g., -echo), it means that specific feature is currently disabled.

How to Change Specific Settings

You can instantly modify how the terminal interacts with your keyboard by passing arguments directly to the stty command.

Fixing the Backspace Key

On some misconfigured remote servers, pressing the Backspace key might print strange characters like ^H or ^? instead of actually erasing the text. You can force the terminal to interpret your Backspace key as the standard “erase” command by running:

stty erase ^H

(Note: To type the literal ^H character in the terminal, you must first press Ctrl+V, followed immediately by Ctrl+H).

Disabling Text Echo

By default, every time you press a key, the terminal echoes (prints) that character to the screen so you can see what you are typing. When writing a bash script that asks a user to input a sensitive password, you must temporarily disable this echo feature so the password does not appear in plain text on the monitor.

You can disable the echo feature by adding a minus sign:

stty -echo

The terminal will now blindly accept input without displaying anything. To restore normal functionality once the password is captured, you simply turn the feature back on:

stty echo

The Emergency Reset Command

If you accidentally cat a raw binary file to your screen, the terminal will often interpret the random binary garbage as stty control codes, instantly corrupting your session and rendering the prompt unusable. Instead of closing the SSH session and logging back in, you can usually force a complete factory reset of the terminal line settings.

stty sane

Even if you cannot see the letters as you type them, carefully typing stty sane and pressing Enter will instantly restore the standard, default TTY configuration, bringing your corrupted terminal back to life.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.