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 Answer
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:
sync
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.
-
worked like a charm. Thank you! Will respect to the system files from now. _/_ Sep 12, 2014 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. Sep 12, 2014 at 14:34 -
1Having
sudo
privileges does not mean you can do root operations without pre-pending it. It just means it will let you usesudo
successfully. Sep 12, 2014 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. Sep 12, 2014 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. Sep 14, 2014 at 23:03
sanchit:x:0:0:Sanchit Jain,,,:/home/sanchit:/bin/bash
it wassanchit: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