Linux – Why does password prompt lag slightly after typing the username in tty

linuxSecuritytty

I have this kind of behavior and I don't know how to fix it or even how to search a fix for it since I don't know how would I even call it.

Here's what's happening:

The first time I boot, when I type out the username and press Retrun the password prompt appears about a half or a quarter seconds later. The problem is that after I type the username I usually press Return and immediately start typing the password; however since the Password: hasn't appeared yet, the tty starts printing the characters I type directly onto the screen.

For example, let's say my username and password are: Username and Password respectively.
If I were to login in a tty1 it would look something like this. The "Pa" at the beginning is there because I had started typing "Password" before Password: actually appeared.

Debian GNU/Linux stretch/sid hostname tty1

hostname login: Username
PaPassword:

A simple solution to this would of course be to type the username and wait a little before typing out the password, however I wish to get to the bottom of this and find the cause of this problem. I have a fear that some day the prompt could lag a lot longer than a quarter of a second (e.g. few seconds) and I would have accidentally typed my whole password onto screen before the Password: finally appeared.

Is there a way to know what's happening here?

Best Answer

The default behaviour of the TTY is to echo (immediately display) whatever the user types to the screen. This provides instant feedback of keys pressed. This is the mode the TTY device is in when the login: prompt is shown.

Before asking for the password, the login program makes a system call to change the mode of the TTY to not echo typed characters (so that your password is not shown as you type it). However, if you start typing characters before the login program actually executes that system call, then those characters will indeed be shown.

After asking for the password, the login program sets the TTY echo mode back to the default (echo what the user types).

Related Question