19

I loaded ubuntu into virtualbox. It all works well but it occurred to me that I was not asked (or did not setup) a root password. I want to use root on occasion, but I cannot seem to find out how to do this. I've tried to access the sudoers file as well as run visudo but have no authority without root!

Any ideas how to get or setup root password?

I do have a root user in /etc/passwd. The two accounts I have do not have authority to even manage groups, because it asks for root password and I don't know it!

1
  • 1
    Off-topic, but try sudo su.
    – casablanca
    Commented Dec 13, 2010 at 0:51

5 Answers 5

28

Ubuntu uses sudo by default. If you preface your command with "sudo" it prompts for your user password and then runs it as root. To get a root session use:

sudo -i

To enable the root account, open a terminal and run the following to set a root password:

sudo passwd root

For more information see:

https://help.ubuntu.com/community/RootSudo

3
  • Just to extend slightly (and summarise the link above), by default you cannot log in as root in Ubuntu, but it is possible to set a root password but is not recommended (or actively discouraged)
    – David O'Meara
    Commented Dec 13, 2010 at 0:55
  • sudo is fine, but if I want to run some cron jobs which cant require password I need to run it as root. So I dont understand this Ubuntu policy about root.
    – Čamo
    Commented Jun 18, 2020 at 20:52
  • You should add a separate question for that really, but that can be achieved by editing roots crontab using sudo crontab -e
    – dsas
    Commented Sep 16, 2020 at 21:49
2

I agree with dsas : Boot into rescue mode, then add the user to admin group :

  1. Restart the virtual machine. Hold Shift during boot. Select Recovery mode when menu shows up. The system will not ask for any password.

  2. Type these

usermod -G admin rob

Now rob has admin permissions, you could restart the virtual machine ('reboot'), and run 'sudo su' to access root shell (the system would ask for rob's password, not root's password)

0

Did you use a pre-existing virtual box image or install from cd/iso ? If you installed from someone elses image then there may be a "ubuntu" user that has sudo privs. Check the documentation.

Alternatively boot into rescue mode and add your 'rob' user to the admin group.

6
  • 'rescue mode' is for disaster recovery, not adding users to the admin group. A 'visudo' command or 'sudo vi /etc/sudoers' should be sufficient. Commented Dec 13, 2010 at 1:24
  • 2
    The problem is that the OP doesn't have sudo access, he cannot fix that by running visudo or sudo vi /etc/sudoers as they both require that he has sudo access.
    – dsas
    Commented Dec 13, 2010 at 1:39
  • No, the problem is that OP doesn't know the root password- "it asks for root password and I don't know it!", to quote. Booting into rescue mode won't get him anywhere. Commented Dec 13, 2010 at 1:41
  • There generally isn't a root password on Ubuntu. The OP has clarified that the user accounts he does have access to don't have sudo access. Booting in rescue mode as far as I remember gives the option to start a shell as root where he can reset the root password or give sudo access to one of the other user accounts.
    – dsas
    Commented Dec 13, 2010 at 1:46
  • Oh, in that case you're talking about single-user mode, which isn't the same as 'rescue mode', where you typically perform rescue operations. Commented Dec 13, 2010 at 2:11
0

Nizam is correct. I have virtual box with ubuntu 20.04 installed on ubuntu 18.04 and it worked for me. I did following:

osboxes@osboxes:~$ sudo su 
root@osboxes:/home/osboxes#

I don't know why he is given -2. I have reduced -2 to -1.

Zulfi.

1
  • You should either use sudo or su. As you cannot use su in Ubuntu by default, something like sudo bash would suffice.
    – Eike
    Commented Oct 16, 2023 at 9:47
-1

If you're on osboxes image, for Ubuntu try this in terminal:

sudo su

Enter password

osboxes.org

4
  • 1
    (1) sudo asks for the user's password. What is "osboxes.org"? (2) The user doesn't have sudo access, so this will just result in an error message. Commented Nov 28, 2018 at 3:27
  • @Scott lmgtfy.com/?q=osboxes.org Commented Nov 28, 2018 at 9:42
  • For some weird reason, the only way to become root in osboxes.org is the way that I mentioned. If its wrong, prove it. Commented Nov 28, 2018 at 9:47
  • 1
    OK, so they provide pre-made VMs for people who don't want to go through the hassle of installing them properly.  This information, if correct, may be valuable.  But somebody else agrees with me that it's not an answer to this question.  I suggest that you ask a new question about OSBoxes and post your answer there.  I'm not going to download software from a site of unknown trustworthiness, but I expect that dsas's answer regarding "rescue mode" / "single-user mode" will work on an OSBoxes VM. Commented Nov 28, 2018 at 18:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .