Understanding Why Terminal Doesn’t Let You Type a Password

Feb 4, 2015 - 17 Comments

Cant type a password into the Terminal? Yes you can, it just doesn't show up

Sometimes you need to enter a password into the terminal, usually for sudo or su commands, which lets users execute a command with super user privileges. This is fairly typical for allowing access to read or modify something that would otherwise not be possible with a standard user account. You’ll commonly see sudo prefixing another command, looking something like “sudo nano /etc/hosts“. Though most of the command line and sudo is generally only appropriate for advanced users, occasionally more casual computer users may need to turn to the Terminal, perhaps to enable a feature, modify a system file, or even for troubleshooting purposes. For novice users who wind up at the command line, a very common question occurs with entering passwords into the Terminal, almost always related to sudo and the apparent inability to type a password into the command line of OS X (or Linux for that matter).


But here’s the thing; Terminal does let you type your password, it just doesn’t look like it. The cursor on screen will not move, and there is no indicator the password is being entered at all. This is intentional and serves as a security mechanism, unlike entering a password into a web form or a standard GUI login screen, which is typically masked as asterisks like ******** or bullets like •••••••••••••, the lack of anything showing is entirely intentional and there is no such indication of entering passwords at the command line. The reason is rather simple, it provides no indication for how long a password is, offering some further obfuscation to password entry.

If this sounds confusing, it’s not at all, here’s how it works in practice. Let’s say you execute a command that requires sudo access, thus bringing up the familiar “Password:” entry.

% sudo cat /etc/secret.conf
Password:

When the Password: request comes up, type the password anyway, even though nothing is showing up then hit Return when finished. Again, there is no indication that a password is being entered, and that is intentional.

Terminal won't enter a password visibly, but it is entered

So let’s run through the prior example command again, pretending the admin password on this particular machine is “Monkey123”, you’d type that password as it’s requested, despite not showing up at all, meaning the sequence would be something like:

% sudo cat /etc/secret.conf
Password: Monkey123 (hit Return key)

This will execute the command. And no, Monkey123 (or whatever the admin password is) will not appear on screen, neither will any asterisks or bullets.

Typing a password into Terminal won't show up, this is intentional

Typically a user only has to experience this once or twice to understand that’s how it works, but it remains a great question for users who are just starting to get exposure to the command line. And once you know, you can pass the knowledge along to others, so if someone asks you “why doesn’t the Terminal let me type a password?”, you can now answer and explain it to them.

For those wondering, yes this default behavior can be changed to show asterisks for each character entered as the password in the command line, for sudo, su, or whatever else you’re doing. Nonetheless, making that change is not recommended, and we’re not going to cover it in this particular article… perhaps in the future if there is some interest in doing so.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Paul Horowitz in Command Line, Tips & Tricks

17 Comments

» Comments RSS Feed

  1. TD says:

    Other programmers deal with the issue of number of characters by inserting a random number of asterisks for each key pressed. Then at least you know its accepting keyboard input.

  2. Gomrl says:

    The other question is why you cannot sudo in Terminal as a standard user but need to be logged in as an admin user.

    • rpk says:

      Users with permissions to ‘sudo’ are stored in /etc/sudoers – which will generally contain a line allowing ‘admin’ users to run sudo.

      The permissions on /etc/sudoers is root read-only, so you’ll need to be in an ‘admin’ group to view it – but then only if you have permissions to run ‘sudo’.

      Try:

      cat /etc/sudoers

      and you’ll get:

      cat: /etc/sudoers: Permission denied

      Now if you’re in the ‘admin’ group, type:

      sudo cat /etc/sudoers

      ps. don’t be daft and try to edit /etc/sudoers with something like ‘nano’.

      You need to use ‘visudo’ – which locks the file against multiple simultaneous edits and opens up the file in the ‘vi’ or ‘vim’ editor.

      You can totally screw your system up if bugger up this file, which is highly likely if you’re unfamiliar with using ‘vi’ or the correct syntax the file requires.

    • Daniel Ebeck says:

      There is a way around this, as long as you know the credentials for an admin user. Just use the “login” command from the standard account to switch to an admin user in the Terminal. Then you can use sudo as much as you like. Use “exit” to get back to your standard user.

  3. Avenged110 says:

    This is so annoying. That and the fact that I can’t enter a blank password. I get so sick of having to go make a password just to enter a command.

    What I don’t understand is if its hidden/can’t enter a blank password “in the name of security,” who cares, I’m sitting in front of the computer. Who/what are they keeping it secure from? The guy looking over my shoulder?

    • Not Torvalds says:

      Yes actually, it may sound weird but this actually is designed to prevent password snooping from ‘the guy looking over’ your shoulder. The invisible password thing has been part of BSD and Unix since the 70’s, a very long relic. Nowadays, if you have a secure and reasonably long password, it may not be as important, but imagine an unscrupulous individual discovering someone had a 1 to 6 digit password? That would be easy to set that as a parameter and guess and/or run a dictionary file against the digit match, thus, this security measure exists. This is from AT&T and Unix, it’s in all Linux distros too, it’s not just Mac OS X or Apple.

    • Raven says:

      Why on Earth would you want a blank password? Don’t be lazy.

      • bernard cleyet says:

        “Why on Earth would you want a blank password? Don’t be lazy.”

        Because I’m very tired of having to look up a password for every little thing. The only important (for me) password is my bank’s. I’ve stopped using face book and other (likedin, etc.), because of passwords. So I use enter (CRLF) whenever permitted.

        Unfortunately, I thought my question [How does one find the password for sudo?] was being answered. Not incidentally, all the ones I’ve tried result in “try again”.

        bc

        • Gin says:

          The sudo password is the same as the admin / root password

          Try using an easy mnemonic to remember passwords. Even something like “IHatePasswords321” would be better than nothing.

  4. KarolaM says:

    Thank you for your posting, good explanation; it worked for me even though I am not a techie. Appreciate your time spent on detailed narrative.

  5. DanD says:

    Unfortunately for me my password does not seem to work under OSX 10.11. I know I am typing it right but it still says “su: Sorry”.

    • Sophie Lazar says:

      SO, if this helps anybody… First i had the admin password on my 10.8.5 mac set for the admin, so I would enter it, (wihtout seeing it as explained above) and it would still say sorry no..
      Then I changed it to no passoword and tried that. I went back to the system preferences/user/groups/ and under the column for the list of users and admin, where there is a + and a – symbol, next to that is a little settings wheel. I had done a fresh install of my OS, and there was no MASTER PASSWORD set, even though there was an admin password set. I set the master password, and VOILA! bingo, sudo password joy>>. it took a second to think about it, and then ran my command. booya

  6. Edoardo says:

    I’m trying to delete stuff from my mac with the sudo command but when i reach the point where i need to enter the password in the terminal instead of the usual grey rectangle there is a key inside that won’t let me type anything even if i type the password (btw i know that nothing should appear) and then press enter it would say ‘sorry try again’
    Have you got any idea what my problem is????

  7. rick says:

    I attempted to set new root password but I failed.When I set new root password in comand line word won’t show up.Keyboard was certainly worked.I can not understand this cause.

  8. anthony says:

    my terminal wont let me install a photoshop plugin, it keeps giving me error reports Failed to get extension handle by extension name, status = -406!
    Failed to install, status = -403!

  9. Korrilius says:

    See my problem is that when I press enter, the Teminal just exits all together, anyway I can fix this?

  10. I did what you suggested but the computer told me my password could not be found and it printed my refused password

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Recent Posts