This article discusses the various superuser commands available in Linux which can be accessed from the command line.
Normal users, for the most part, can modify only the files they own. One special user, called the superuser or root, has full access to the machine and can do anything on it. You should rarely need superuser privileges; and in fact, you should use them only when absolutely necessary, to avoid accidentally harming your Linux system.
You can become the superuser in several ways. One is to use the sudo command to gain superuser abilities for the duration of a single command. Simply type “sudo” followed by the command. You may be prompted for your password, depending on how sudo is configured on your machine:
sudo rm protected_file Password: ******** Your own password
To make your superuser powers last for multiple commands, you can run a shell with sudo:
This is convenient, say, before browsing through many protected directories with cd. When finished executing commands as the superuser, type ^D or run exit to end the superuser shell and become yourself again. If you forget whether your shell is a superuser shell or just a normal one, check your identity with the whoami command. If you’re the superuser, it will display root.
Another way to become the superuser is the su command, which also creates a superuser shell, but you’ll need a different password, called the root password, to use it. If you don’t know the root password on the system, you can’t use su. (If you installed Linux yourself, you chose the root password during installation):
su -l Password: ******* #
Your shell prompt may change, often to a hash mark ( # ), to indicate you are the superuser.
If you provide a username to su:
su -l sophia Password: *******
you can become that user (provided you know her password).
Note sudo and su have important differences. su is standard on every Linux system, but you need a password other than your own in order to run it. sudo uses your own password, but it must be configured to do so. sudo is superior for systems with multiple superusers, as it provides precise control over privileges (in the /etc/sudoers file) and even logs the commands that get run.
This article has presented the most common Linux superuser commands and options that can be accessed at the command line.