If you have forgotten the user (or root) password on an Ubuntu system, follow these steps and you will be able to login and start using the machine again.
When the machine is booting, keep the Shift key pressed; this will invoke the Grub menu.
The menu will look something like this.
Select the Advanced mode and Select the recovery mode from the shown menu. (In some cases you may be able to select the recovery mode menu from the above menu itself).
In the recovery menu, select the root option.
The command prompt will now be shown.
The file system is not available for Write now. It has to be mounted with RW permissions. As the user/password information is stored in the file system and we are updating the same, we will need to have the Read Write permissions. Execute the following command.
mount -rw -o remount /
Now you can execute the passwd command to change the password.
You will be prompted for the new password.
If you want to create a new user, before executing the passwd command, use the useradd command to create the new user and update the password using passwd command.
If everything went fine, you will be able to restart the machine and login with the new password.