How do you change the root password on Debian?

  • I want to change the password I assigned to root on my Debian webserver to something longer and more secure.

    How do I do that? I haven’t forgotten/lost the current password, I just want to change it.

    To find this out for yourself, run `apropos password`: you'll get a list of commands that contain “password” in their short description. You can narrow the search a little with `apropos -s 1 password`: `-s 1` restricts to section 1 of the manual, which contains user commands.

    @Gilles: that’s fantastic, I had no idea.

    Have you considered, instead, `sudo`.

  • Ah, use the passwd program as root:

    sudo passwd root
    

    Or, if you’re running as root already (which you shouldn’t be), just:

    passwd
    

    The root argument can be omitted, because when you execute passwd it defaults to the current user (which is root, as only root can change the root password).

    Obvious in hindsight, really. :)

    @Shadur: *painfully* :) I’d just never done it before, and the Google links I found first were for folks who had forgotten the root password.

    Should be `sudo passwd`, or just plain `passwd` if you are running with root privileges.

    @phunehehe: ah, gotcha. Answer edited; do I need `root` after `sudo passwd` if I’m not running as root?

    @Paul I took liberty in editing your answer. There are a few ways to run things as root, and when `passwd` is run as root, it defaults to modify the `root` user.

    @phunehehe: excellent, much appreciated.

    Maybe should say su -c 'passwd root' for systems like CentOS, Fedora, RHEL where sudo isn't installed. This would help teach newbies not to run as root by default.

    Did you ask this to get self-rep... it's on the first page of google results!

    @jamespo: no. When I Googled initially, I only noticed links saying how to reset a lost root password. I do tend to ask on SE sites quite quickly, but only to make the answer easy for me to find in the future.

    @PaulD.Waite It's worked, but when i'm going to login via Ctrl+Alt+F1 , it's says incorrect login!

    @Mr.Hyde: rough spot.

    @Katerberg You can just use su -c "passwd"

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM