Occasionally I'll want to change the password for a user and I'll type passwd, but I'll be logged in as root and I'll wind up changing the root password. I definitely don't want to do this in Ubuntu (because I prefer that air of mystery).

Is there a hidden key combo that'll get me out of the prompt:

Enter new UNIX password:

ctrl-c, etc. not working.

I've noticed this in Ubuntu, SLeS and Centos, I think.

My goto so far has just been to go to another tty and kill passwd (is this a bad idea?)

  • Your idea is not bad. But the easiest way to type 2 different passwords, then it'll be failed. – Ipor Sircer Dec 21 '17 at 17:22
  • @IporSircer that seems like it should be posted as an answer. (Ideally, fleshed out a little.) – derobert Dec 21 '17 at 17:23
  • @ipor does it ask you to re-type the password? I thought there were some cases where it didn't. (I didn't want to try this time) – Peter Turner Dec 21 '17 at 17:25
  • IporSircer doesn't seem to want to put a proper answer, so I'll go ahead and do so... – derobert Dec 21 '17 at 17:41
  • 2
    function passwd() { if [ $# = 0 ]; then echo Usage: passwd username; else command passwd "$@"; fi } – Mark Plotnick Dec 21 '17 at 17:43

As IporSircer suggested in a comment, you can enter one password then another at the confirm prompt. There isn't anything wrong with your approach either; passwd doesn't actually start updating the password database until after you've entered and confirmed the password (and even that it should be doing in an atomic manner, so kill won't break it).

At least on my systems, you can also just hit enter a bunch; empty root passwords are rejected (but that's less safe, some systems may permit it).

Two other things to note: First, the root prompt and user prompt by default look different. The root prompt uses #; the user prompt $. That's on purpose—so at a glance you can see you're logged in as root. Also it sounds like you're logged in as root far too often if you're making this mistake routinely. Consider only logging in as root when you need to, using sudo, etc. You could also, as Mark Plotnick suggests in a comment, add a passwd function to your root shell to prevent changing the root password by mistake: function passwd() { if [ $# = 0 ]; then echo Usage: passwd username; else command passwd "$@"; fi }. (You'd add that, e.g., to root's .bashrc after checking that its an interactive shell)

Second, the initial root password on Ubuntu isn't a mystery, there just isn't one (the password hash field is set to a value that no password can possibly match). You should be able to restore that state with usermod -L root or passwd -l root.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.