Tame Your Terminal Echo: Control Input Display with `stty`
Quick Tip
Tame Your Terminal Echo: Control Input Display with `stty`
Challenge: Sometimes you need to input sensitive information (like passwords) into a script or command without it being visible on the terminal for security or to prevent accidental display. By default, terminal input is echoed back to you.
The Solution: Use the stty -echo command to temporarily disable terminal input echoing, and stty echo to re-enable it.
# Disable echoing stty -echo # Prompt for sensitive input (e.g., password) read -p "Enter sensitive data: " sensitive_data # Re-enable echoing stty echo # Now you can use $sensitive_data in your script echo "Data entered: $sensitive_data"
Why it works: The stty command is a utility that changes and prints the terminal line discipline settings. The -echo option specifically disables the local echoing of input characters to the terminal, making them invisible as they are typed. Conversely, echo re-enables this behavior.
Pro-Tip: You can also use `stty -icanon` to disable canonical mode (line buffering) for more advanced real-time character processing if needed, but remember to restore it with `stty icanon`.
Linux Tips & Tricks | © ngelinux.com | 6/7/2026
