To get root access to my existing account in ubuntu i followed this post. But even after following the steps mentioned i wasn't able to create/modify file or directory without using the sudo keyword. Then i found one post which suggested that i can change the /etc/passwd and modify my username to match root:x:0:0:root:/root:/bin/bash. I followed, rebooted the system and then instead of my name in the welcome screen I saw the guest instead. While searching the net I found that root user is locked in ubuntu. Because i modified my username to match the root user, even my account is locked ( i think). How can i get it back? sudo is not working with guest account (as expected)

  • 1
    How exactly did you modify your username entry to "match" that of root? Have you actually tried rebooting into recovery mode and dropping to a root shell? – steeldriver Sep 12 '14 at 13:02
  • my bad, the statements were a bit ambiguous ....ofcourse i cannot modify my username to root, but matched the other parameters exactly similar to root. Here is how the user is listed in the /etc/passwd file sanchit:x:0:0:Sanchit Jain,,,:/home/sanchit:/bin/bash it was sanchit:x:1000:1000:Sanchit.. before i made the changes, i dont remember if i made any changes to last part of the line i.e. is to the :/home/sanchit:/bin/bash part – Sanchit Jain Sep 12 '14 at 14:05
  • i haven't tried to reboot into recovery mode, as I am not aware of it. Will google it and try it. – Sanchit Jain Sep 12 '14 at 14:07
  • @asteeldriver, AFAIK that requires you to set the root password before the incident, but I could be wrong. I added an alternate solution as an answer. – Andrea Lazzarotto Sep 12 '14 at 14:14
  • why is the question down voted? – Sanchit Jain Sep 14 '14 at 14:33

Boot your PC while holding Ctrl+Shift, you should see the GRUB menu appear. While focusing on the first Ubuntu entry, press e to edit it.

You should see a line which ends with ro quiet splash --. Change this last part to:

rw verbose init=/bin/bash --

Don't touch the first part of the string, leave it the same as before. Now press Ctrl+X to boot. You should boot straight into a root shell. Now type:

sudo passwd sanchit

Choose a new password for your user. To recover the modified information, you should also do:

sudo nano /etc/passwd

Restore the correct user id and group for your user (they are both 1000 instead of 0). Now type the following command to mount your filesystem back in read only mode:

mount -o remount,ro /

Now switch off your PC using the power button. Turn the PC on again and it should work. If I can add a bottomline: next time, think twice before making these kind of changes to system files.

| improve this answer | |
  • worked like a charm. Thank you! Will respect to the system files from now. _/_ – Sanchit Jain Sep 12 '14 at 14:28
  • Can you please help me with my original problem too? I want to grant root privileges to the user. I tried to do it using sudo usermod -a -G sudo sanchit as told here. But even after this whenever i want to create a file or folder i have to prefix my commands with sudo. – Sanchit Jain Sep 12 '14 at 14:34
  • 1
    Having sudo privileges does not mean you can do root operations without pre-pending it. It just means it will let you use sudo successfully. – Andrea Lazzarotto Sep 12 '14 at 15:16
  • Surprising.... i am using Sublime Text Editor. And i am not able to create new file using it, as sudo privileges are required. So i have create a file in terminal, provide read/write by chmod and then only i am able to work on the file, which is very cumbersome. – Sanchit Jain Sep 12 '14 at 16:25
  • If you want to create a file as root, you must run the application by prepending gksu in front of the command. Then you can save the file successfully. – Andrea Lazzarotto Sep 14 '14 at 23:03

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.