One thing that annoys me using Linux's terminal is when I have to type a invisble password, like when you run ssh. Sometimes I mistype one or more letters and then I have to press backspace key a few times to make sure that I erased everything to start again.

I know this is not a big deal but since on the other day I found out that pressing CTRL+L "clears" the terminal I was wondering if there's a way to clear/erase the invisible password without relying on backspace or pressing enter key to try again.

I know this was already answered, but the answer doesn't explain what's going on.

Characters like Ctrl+L are handled by the application. In the case of entering input into the shell, like bash, it clears the screen. Some applications, like emacs, use it to redraw the screen and/or recenter the cursor.

Characters like Ctrl+U at a password prompt are handled by the TTY line discipline. They'll work any time the input terminal is in the "canonical" line-editing mode, which is what mode your programs are in while you're entering a password. In this mode, it's the Linux kernel itself that is interpreting these characters. You can see what functions are assigned to which keys in the output of stty -a:

Here, you can see that Ctrl+U is tied to kill, which (according to the stty man page) will "erase the current line". You could also use stty to change this mapping:

stty kill ^E # make ctrl-e erase the line

This page has a lot of great information about the TTY layer if you're interested.

If things weren't confusing enough: when at the prompt of an interactive bash, you're actually not in the "canonical" line-editing mode. Instead, bash is receiving each character directly as you type it, and interpreting the control sequences itself, through the readline library. This library will honor the mappings you've set on your terminal device, though, so you can still use stty to change them. Or, you can customize them independently inside bash and other readline-based programs by setting the unix-line-discard property inside your ~/.inputrc file. See the bash man page for more info.

When you run a program, bash re-enables canonical line editing mode (stty icanon) if it was enabled before, and then disables it again when the program finishes (stty -icanon).