-2

I have an active root account, but I don't know my password.

To be able to change my password or even to create another users (with the tool passwd) I need to know my password. So that creates a problem. But since I'm root - am I allowed to replace arbitrary binaries in /bin/ directory? Just modify passwd source code, compile it, replace the original one with the new one. Is it that simple? Any caveats?

My test systems are: FreeBSD 11.0 + Ubuntu 18.04

  • 3
    Why can't you just set a new password for root? – Jeff Schaller Aug 8 '19 at 18:32
  • What OS? (Linux? Some BSD?) – ilkkachu Aug 8 '19 at 18:32
  • Is it that simple? But i need to know old password in order to change my password? I heard that it was possible to create users without any passwords. Is it still allowed on modern unix/linux systems? – Awaaaaarghhh Aug 8 '19 at 18:34
  • 4
    root can change passwords without knowing the old password. – jesse_b Aug 8 '19 at 18:35
  • You cannot create new users using passwd. But yes, if you have root privileges you can replace any binary on the system with anything you wish. – doneal24 Aug 8 '19 at 18:38
5

Most Linuxes I've seen are configured so that passwd doesn't ask root for the old password:

root@xxx ~# passwd root
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

Even if passwd does ask for it, you could try chpasswd, or edit /etc/passwd and /etc/shadow by hand (the password hash is the second field, the long blurb of characters between two colons) It's just that you'd need to compute the hash first, openssl is just one of the tools to do that:

$ echo foobar | openssl passwd -1 -stdin
$1$G/nr44th$wn16q7ITSvfrNq4amDfzn1

(You probably shouldn't really use the MD5-based $1$ hash, but it doesn't matter since at least after resetting the hash to a known value, you could use passwd to change it.)

  • I read somewhere that one just can edit entries in /etc/passwd and /etc/shadow. Would it cause any problems? Is there any benefit from using passwd tool instead of doing it by hand? - I'm worrying about system stability and less about user friendliness which offers passwd tool. – Awaaaaarghhh Aug 8 '19 at 18:39
  • @Awaaaaarghhh, you can edit passwd and shadow by hand. Or rather with vipw/vipw -s. You probably shouldn't do that on important systems, since well, there's always the chance of a typo leaving it impossible to log in. It probably helps to keep a root session open and test logging in before closing it. Actually you – ilkkachu Aug 8 '19 at 18:41
  • Because my question was so heavily downvoted (I guess I asked a really stupid question) I would like to delete it. Is there any way to do that? – Awaaaaarghhh Aug 8 '19 at 18:42
  • @Awaaaaarghhh, I'm not sure how it works. It doesn't let you delete it because of an upvoted answer? – ilkkachu Aug 8 '19 at 18:45
  • 3
    It is not a stupid question, but it is not asked well. It is not clear what you are asking: are you asking “How do I regain access to my system?”, “I have access, but don't know the password. How do I change my password? And this is what I have tried.”, “I am curious about what can root do. Can root change anything on the system?”. If the question was clear, then I would have up-voted. As for deleting: I think you can vote to close, then when closed, you can vote to delete (I am not an expert in this area). – ctrl-alt-delor Aug 8 '19 at 21:44

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.