Making Your Terminal Sane Again

Problem

You have aborted an SSH session and now you can’t see what you are typing. Or perhaps you accidentally displayed a binary file and your terminal window is now gibberish.

Solution

Type stty sane and then the Enter key, even if you can’t see what you are typing, to restore sane terminal settings. You may want to hit Enter a few times first, to make sure you don’t have anything else on your input line before you start typing the stty command.

If you do this a lot, you might consider creating an alias that’s easier to type blind.

Discussion

Aborting some older versions of ssh at a password prompt may leave terminal echo (the displaying of characters as you type them, not the shell echo command) turned off so you can’t see what you are typing. Depending on what kind of terminal emulation you are using, displaying a binary file can also accidentally change terminal settings. In either case, stty’s sane setting attempts to return all terminal settings to their default values. This includes restoring echo capability, so that what you type on the keyboard appears in your terminal window. It will also likely undo whatever strangeness has occurred with other terminal settings.

Your terminal application may also have some kind of reset function, so explore the menu options and documentation. You may also want to try the reset and tset commands, though in our testing stty sane worked as desired while reset and tset were more drastic in what they fixed.

See Also ...

Get bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.