Changing to a different user sudo and su

From docwiki
Jump to: navigation, search


Motivation

In order to administrate your system you need to have root (super user) privileges. After you have setup your own Linux system, the first thing that you need is to become root

Find out which user you are

$ id

Tells you which username you are and the numeric id of your user and also which groups you are assigned to.

Change to a different user

The 3 most important ways to change to a different user are:

  • login as a different user. This requires that you have the password of the other user and often login as root user is not allowed on the GUI.
  • su - The su stands for "super user" and allows you to become root or any other user if you know the passwords. The minus sign (-) is not necessary but useful: It tells the su that you want to have the same environment as you would have after login. (E.g. the root user typically has other settings then mortal users)
  • sudo su - sudo allows you to run any command as he root user. This of course requires that sudo is installed and is configured in a way to allow you run those commands. On typical live systems (that you can boot from CD or thumbthrive) the sudo is configured so that you can run any command without passwords. On normal system you will need to enter your password in order to use sudo. When you want to be root for longer period of time you can use the sudo su - instead of prefixing everything you want to run as root by sudo.

Exercises

  • Boot with a Live System and try to become root.