Difference between revisions of "Lost sudo"

From FreekiWiki
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
In Xubuntu (and other Ubuntu-derived operating systems) there isn't a true root user account, so in the majority of cases system administration will be performed by a user capable of using the <code>sudo</code> function to gain superuser privileges.
+
In Xubuntu (and other Ubuntu-derived operating systems) there isn't a designated administrative ("root") user account, so in the majority of cases system administration will be performed by a user capable of using the <code>sudo</code> function to gain superuser privileges. If a system has multiple users you may want to restrict the ability to use <code>sudo</code> to only those trusted to add or remove software and make configuration changes to the computer.
  
If you are ever prompted for the root password and do not have the option to provide the password for any of the user accounts on your system the problem is likely that none of your user accounts have authority to use <code>sudo</code>.  
+
At least one user will need to have <code>sudo</code> privileges in order to effectively maintain your system. In some situations a user mistake or software bug could cause you to be left without any accounts that can use <code>sudo</code>. If you find yourself being prompted for the root password and do not have the option to provide the password for any of the user accounts on your system the problem is likely that none of your user accounts have authority to use <code>sudo</code>. The instructions below will help you correct this.
  
 
==Booting into Recovery Mode with GRUB==
 
==Booting into Recovery Mode with GRUB==
Line 16: Line 16:
 
   root@freekbox:~#
 
   root@freekbox:~#
  
Proceed to the "Restoring sudo" section of this page.
+
Proceed to the "Adding sudo privileges" section of this page.
  
 
===Xubuntu 12.04 ===
 
===Xubuntu 12.04 ===
Line 33: Line 33:
 
   mount -o remount,rw /
 
   mount -o remount,rw /
  
==Restoring sudo==
+
==Adding sudo privileges==
  
If you are certain of the specific username you need to give sudo privileges to then skip to to ''Adding a user to sudo''. Note that your proper username may not be the name you usually see at the login screen; a full name like "John Smith" is not a proper username, but a shorter, simpler name like "jsmith" is likely to be correct.
+
To add sudo privileges you need to be able to specify the exact username to add them to. Note that the name displayed on your login screen may not be the same as your formal username, instead being a "friendly" name that you provided at some point. For example, if your name on the login screen reads something like "John Smith" then that is almost certainly the "friendly" name, while your formal username is likely to be something more like "jsmith". If you're certain you already know the username you will be using then skip to the section ''Adding a user to the sudo group''.
  
 
===Identifying usernames===
 
===Identifying usernames===
  
If you're unsure what the exact username you need to add is, type the following command:
+
Type the following command:
 
   cat /etc/passwd
 
   cat /etc/passwd
 
A large list will appear, containing lines such as
 
A large list will appear, containing lines such as
Line 45: Line 45:
 
   bin:x:1:1:bin:/bin:/bin/false
 
   bin:x:1:1:bin:/bin:/bin/false
 
   jsmith:x:1000:100:John Smith:/home/jsmith:/bin/bash
 
   jsmith:x:1000:100:John Smith:/home/jsmith:/bin/bash
In that example the first two lines are system accounts, but the third line is a user account that could be granted sudo access, with the first word of it (jsmith) being the correct username.
+
In that example the first two lines are system accounts, but the third line is a user account that could be granted sudo access, with the first word of it (jsmith) being the correct username. User accounts can be distinguished by the number after the second ":" being 1000 or greater, and they will usually be towards the bottom of the list. If the list is particularly long and you don't see anything that fits the criteria (often the case when the Guest account has been used a lot) you may need to scroll up the list by pressing Shift+PageUp. Press PageDown to return to the command prompt below the list.
  
===Adding a user to sudo===
+
===Adding a user to the sudo group===
  
 
Type the following command and press Enter to create a back up of your group settings:
 
Type the following command and press Enter to create a back up of your group settings:
 
   cp /etc/group /etc/group.bak
 
   cp /etc/group /etc/group.bak
 
Type the following command, substituting the desired user for the example "jsmith":
 
Type the following command, substituting the desired user for the example "jsmith":
   useradd -G sudo jsmith
+
   usermod -a -G sudo jsmith
 
Restart your system with the command
 
Restart your system with the command
 
   reboot
 
   reboot
  
Your system will restart and your new account should now be able to use administrative features. If you are returned to the GRUB menu after restarting just press the Enter key to select the default option and boot normally.
+
Your system will restart and the designated user account should now be able to use administrative features. If you are returned to the GRUB menu after restarting just press the Enter key to select the default option and boot normally.
  
 
[[Category:Tech support]]
 
[[Category:Tech support]]

Latest revision as of 13:17, 5 March 2014

In Xubuntu (and other Ubuntu-derived operating systems) there isn't a designated administrative ("root") user account, so in the majority of cases system administration will be performed by a user capable of using the sudo function to gain superuser privileges. If a system has multiple users you may want to restrict the ability to use sudo to only those trusted to add or remove software and make configuration changes to the computer.

At least one user will need to have sudo privileges in order to effectively maintain your system. In some situations a user mistake or software bug could cause you to be left without any accounts that can use sudo. If you find yourself being prompted for the root password and do not have the option to provide the password for any of the user accounts on your system the problem is likely that none of your user accounts have authority to use sudo. The instructions below will help you correct this.

Booting into Recovery Mode with GRUB

Ubuntu 10.04

Note that after performing step 1 you have a limited time to perform step 2, so please read the instructions fully before beginning the process.

  1. Power on the computer (shut it down first or simply reboot if it is already running).
  2. When the BIOS information or manufacturer's logo "splash" screen appears start holding down the right shift key. If your computer does not usually display BIOS information or a manufacturer's logo you may need to start holding down the shift key immediately after pressing the power button.
  3. After a few seconds you will see the GRUB menu, which is characterized by a lines that will say ...kernel 3.2.... If the system continues to boot normally and arrives at the regular login screen or desktop you will need to restart and try again. If you are repeatedly failing to reach the GRUB menu try quickly and repeatedly tapping the shift key until the menu appears instead of just holding it down.
  4. Hit the down arrow key (usually only once) until it arrives on the first line that ends with recovery mode and press enter.
  5. Select "Root" from the recovery mode menu that appears to enter a shell environment with root privileges.
  6. You should now see a prompt at the bottom of the screen that reads
  root@freekbox:~#

Proceed to the "Adding sudo privileges" section of this page.

Xubuntu 12.04

Note that after performing step 1 you have a limited time to perform step 2, so please read the instructions fully before beginning the process.

  1. Power on the computer (shut it down first or simply reboot if it is already running).
  2. When the BIOS information or manufacturer's logo "splash" screen appears start holding down the right shift key. If your computer does not usually display BIOS information or a manufacturer's logo you may need to start holding down the shift key immediately after pressing the power button.
  3. After a few seconds you will see the GRUB menu, which is characterized by a lines that will say ...kernel 3.2.... If the system continues to boot normally and arrives at the regular login screen or desktop you will need to restart and try again. If you are repeatedly failing to reach the GRUB menu try quickly and repeatedly tapping the shift key until the menu appears instead of just holding it down.
  4. Hit the down arrow key (usually only once) until it arrives on the first line that ends with recovery mode and press enter.
  5. Select "Root" from the recovery mode menu that appears to enter a shell environment with root privileges. Note that until further steps are completed your file system will be in "read only" mode and you will not be able to make any persistent changes to the system.
  6. You should now see a prompt at the bottom of the screen that reads
  root@freekbox:~#

Mount the file system in read/write mode by entering the following command at the prompt:

  mount -o remount,rw /

Adding sudo privileges

To add sudo privileges you need to be able to specify the exact username to add them to. Note that the name displayed on your login screen may not be the same as your formal username, instead being a "friendly" name that you provided at some point. For example, if your name on the login screen reads something like "John Smith" then that is almost certainly the "friendly" name, while your formal username is likely to be something more like "jsmith". If you're certain you already know the username you will be using then skip to the section Adding a user to the sudo group.

Identifying usernames

Type the following command:

  cat /etc/passwd

A large list will appear, containing lines such as

  root:x:0:0:root:/root:/bin/bash
  bin:x:1:1:bin:/bin:/bin/false
  jsmith:x:1000:100:John Smith:/home/jsmith:/bin/bash

In that example the first two lines are system accounts, but the third line is a user account that could be granted sudo access, with the first word of it (jsmith) being the correct username. User accounts can be distinguished by the number after the second ":" being 1000 or greater, and they will usually be towards the bottom of the list. If the list is particularly long and you don't see anything that fits the criteria (often the case when the Guest account has been used a lot) you may need to scroll up the list by pressing Shift+PageUp. Press PageDown to return to the command prompt below the list.

Adding a user to the sudo group

Type the following command and press Enter to create a back up of your group settings:

  cp /etc/group /etc/group.bak

Type the following command, substituting the desired user for the example "jsmith":

  usermod -a -G sudo jsmith

Restart your system with the command

  reboot

Your system will restart and the designated user account should now be able to use administrative features. If you are returned to the GRUB menu after restarting just press the Enter key to select the default option and boot normally.