Below is the process I took to create a user on bash in Linux.

$ sudo useradd Alexandra
$ sudo passwd Alexandra
Enter new UNIX password: 
Enter new UNIX password: 
passwd: password updated successfully

I understand that the password shouldn't be displayed for security purposes, but what I mean is, why do asterisks (or the characters I entered) not appear?


3 Answers 3


What's the simplest way of hiding user input?

Not displaying it!

Hiding passwords when they're being typed is an old tradition. In makes sense from a security perspective in most contexts: if someone is looking over your shoulders, you don't want to make it easy to see what you're typing. (Some modern security guidelines e.g. 1 2 3 4 5 do recommend having an option to make the password visible though, because that allows the user to be able to choose more complex passwords and have confidence that they won't be spending their time fixing unseen typos. The biggest risk isn't shoulder surfing, it's brute force guessing, possibly offline.)

Having decided that the password should be hidden, the implementers had to decide how to do it. The terminal has a mode where user input is shown (echo on), and a mode where user input is not shown (echo off). The echo off mode has intrinsic existence in a way: that's the mode where the terminal doesn't do the extra work of echoing user input. This mode also has to exist for applications where typing a key doesn't insert that character, but instead invokes some application shortcut that is bound to that key. So commands like passwd just set the terminal to echo off mode while they're reading a password.

Printing asterisks for each character would require extra implementation work for only a relatively small benefit, which the implementers of the passwd command haven't felt like doing. There's no terminal mode for printing asterisks because it would be a very specialized feature, useful only when entering passwords.

By the way, if you want to see your password when changing it, you can use cat | passwd (at least on some systems — some versions of passwd require an option like cat | passwd --stdin and some don't accept this at all). (You can even do { echo 'current password'; echo 'new password'; echo 'new password'; } | passwd, but don't do that: it would save the passwords in the shell history, from which there's a lot more risk of leaking.) Arranging for that with commands that read the password from the terminal rather than whatever is their standard input, such as sudo or ssh, is more complex; if you have a GUI available, you can use ssh-askpass which does show how many characters you've typed (SUDO_ASKPASS=/usr/bin/ssh-askpass sudo -A for sudo; for ssh it's complicated when you invoke it from a terminal).

  • 1
    This is by far the best answer imo and it's actually very helpful. Thanks for clarifying my belief and expanding ^,^ deserves vote up!
    – DankyNanky
    Mar 6, 2016 at 21:43
  • 4
    The terminal handler takes care of simple editing features (like backspace) and buffering the line. A line read using fgets() doesn't return until enter is pressed. so that makes printing asterisks tricky. If you were to read it one character at a time and echo asterisks you'd lose backspace functionality, or need extra effort to support it.
    – Jasen
    Mar 7, 2016 at 8:16
  • 1
    When going into the history angle on this issue, I wonder how this relates to the time when tty actually referred to teletypewriter...
    – Jasper
    Mar 7, 2016 at 9:43
  • 1
    There are ways to execute a command without it being stored in the command history. See for example Execute command without keeping it in history.
    – user
    Mar 7, 2016 at 12:33
  • 2
    Addendum: Terminals that "do extra work" to echo user input are so-called "full duplex" terminals. In Ye Olde Days there were also "half duplex" terminals, where the character was displayed right away by the terminal upon being typed, and the OS did not send it back to the terminal for display. If I remember correctly, these terminals had no way to turn off echo.
    – alexis
    Mar 8, 2016 at 14:49

Because that's the way we do things in *nix land. :) It gives a little bit of extra security by not displaying a bunch of asterisks. That way, someone who sees your screen can't see the length of your password.

But I must admit it is a little bit scary not getting any feedback when you're entering a password, especially if you've got a bad keyboard. So most GUI password dialog on *nix systems do give you some kind of feedback, e.g. using asterisks, or more commonly ⬤. And some even display each character as you type it, but then immediately replace it with a * or ⬤, but that's not so good if someone may be looking over your shoulder. Or if they have a device that can pick up & decode the video signal being sent from your computer to your monitor.

  • 6
    ... with the help ofstty -echo
    – Jeff Schaller
    Mar 6, 2016 at 17:42
  • 10
    This answer is not bad, but IMHO Gilles gave the real answer. Almost certainly, the implementors weren't really thinking of "a little bit of extra security" and definitely weren't thinking of the user experience. They did it the way they did it because it was cheap and easy to do it that way. Then, later, we came to expect it to continue to work that way...
    – Celada
    Mar 6, 2016 at 20:01
  • 2
    @Celada: Fair point. FWIW, I've already up-voted Gilles' excellent answer.
    – PM 2Ring
    Mar 6, 2016 at 20:04
  • 3
    @Celada The added security may not have led to the original decision to display nothing, but I've always considered it a benefit, and can see how others thinking that way may have provided a good reason to keep it that way. Mar 7, 2016 at 15:43
  • 2
    I think the breif display of the last character typed is mostly a mobile approach, probably because typing on a tiny, on-screen keyboard is more error-prone. I don't think I've ever seen it in desktop applications.
    – Barmar
    Mar 9, 2016 at 18:07

Making the password invisible makes it more secure, as the length of the password cannot be seen by others. This avoids the risk of others trying to guess the password from its length and log in into your account.

  • 1
    Keyboards tend to make some amount of noise as they are used, which can be heard or recorded for later analysis to determine password length. Some keyboard models are quieter than others. Also, some keys tend to make relatively distinct noises (think space bar, Enter, etc.). In this context, also consider How critical is it to keep your password length secret? on Information Security.
    – user
    Mar 7, 2016 at 12:37
  • 1
    @ Michael Kjörling : What you said is an advanced level security and a valid point to be considered (especially for the one's whose hearing power is really good, who can get the password length through the noise of keyboards). But it is a hardware issue, which needs to be considered at hardware level and as such, now we have facility of touch screen keyboards, which do not create noise.
    – Coder AP
    Mar 7, 2016 at 14:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .