I accidentally deleted administrator account and the other accounts are asking root password

I unexpectedly deleted my user account (the only administrator for the machine). I have another account which is a standard account and now I can't access my hard disk or anything with that standard account - it is asking for the root password. Is there any way I can recover access to the administrator account?


Solution 1:

You can use recovery mode to add the standard user to the admin group (which is now called sudo in 12.04). Below is a set of simple instructions copied from my personal website.

Using Recovery Mode To Add Users To The Admin / Sudo Group

First shutdown your computer.

Then restart whilst holding shift on the keyboard to load grub menu.

Select recovery mode from the grub menu.

Select drop to root shell from the recovery menu.

Use the following command to remount the drive mount -o rw,remount /

Now type adduser username sudo replacing username with your user name ie. 'adduser phil sudo'

You should now see a message saying 'adding user' followed by 'done'.

Type shutdown -r now to restart the computer.

EDIT: If it is telling you that user xxx does not exist, first you can use the following command to list users and make sure that you have the correct username

ls /home

The other option is add a new user, from recovery mode using the following commands :

useradd username -m -s /bin/bash  
passwd username
adduser username sudo

Again replacing username with your desired username.