Linux Login as Superuser ( root user )

last updated in Categories , , , , , , ,

How do I login as superuser or root user in a Linux operating systems? How do I become superuser in Linux?

The superuser, or root, is a special user account used for system administration purpose on Linux.

Linux superuser

In Linux and Unix like computer operating systems, root is the conventional name of the user who has all rights or permissions (to all files and programs) in all modes (single- or multi-user). The root user can do many things an ordinary user cannot, such as changing the ownership of files and binding to ports numbered below 1024. The etymology of the term may be that root is the only user account with permission to modify the root directory of a Unix system.

Linux Login as Superuser

You need to use any one of the following command to log in as superuser / root user on Linux:

  1. su command – Run a command with substitute user and group ID in Linux
  2. sudo command – Execute a command as another user on Linux

How to become superuser in Linux

Let us see some examples of the su and sudo command to become superuser in Linux.

Become a superuser in Linux using sudo command

You must be part of special secondary group on Linux:

  • sudo group on a Debian or Ubuntu Linux
  • wheel group on a CentOS/RHEL/Fedora/Oracle Linux

You can see your secondary group membership by running either groups command or id command
$ groups
$ id

Next run the following command to become a root/super user:
$ sudo -i
When promoted type your password to gain root shell.

Linux Login as Superuser using sudo command
Log in as a superuser/root user using the sudo command on Linux

Superuser login – How to become Superuser in Linux using su

Under Linux (and other Unixish operating systems) you use command called su. It is used is used to become another user during a login session or to login as super user. If invoked without a username, su defaults to becoming the super user. It is highly recommend that you use argument - to su command. It is used to provide an environment similar to what the user root would expect had the user logged in directly. Type su command as follows:
$ su -
Sample outputs:

Password: <TYPE ROOT PASSWORD>
#

Once you typed the root user password, you become super or root user.

Exiting from su or sudo session

You simply need to type the following exit command or logout command:
exit
OR
logout
Another option is to press the CTRL and d keys simultaneously to exit from su or sudo session:

How to exit from su or sudo command
How to exit from su or sudo command

See also:

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at www.nixcraft.com

Historical Comment Archive

13 comment

  1. It is interesting to notice how easy it is to find this information on the web, how to login as a superuser, and how it is difficult to find the information about how to log OUT of superuser (exit). Wouldn’t it make sense to put these things together ? I guess that someone who just learnt how to log in as a superuser would also immediately need to know how to log out.
    And by the way, your answer after “A” doesn’t answer the questions “Q” at the beginning of the article.

  2. Hey, i tried this but my linux said:
    Error with approval ( think thats how you translate it..
    its bothering me alot and i tripple checked the password it is correct

  3. what version of lunux are you using? if you are using any ubuntu based linux for example you, you can only use the super user to run comands, you cant stay loged in as the super user.

    Ex: to install an aplication, you would opne a terminal and enter

    sudo apt-get install name_of_application.

    the sudo or su comand will indicate to linux that you are trying to run the comand as the super user or administrator, but in ubuntu after the application is done installing it will go back to regular user to aboid any security breach. y have to realize that the when you are in super user mode it can be verry danguros becasue bc you can do anything, like deleting all you files and messing up your operating system.

    so in conclution you get that message because your linux you might not be running any other comands after the sudo or su comand.

    i hope that made sense.

  4. I am new to linux, i want to learn more about linux as much possible. i am using ubuntu and suse.
    i try to log in as supper user by su command, and provide password i used to login my system but it shows Authentication failure. please guide me.

    Thanks and regards

  5. Earlier i used to login to root by typing ip address and port, i just remember the ip address but i forgot the port number, can anybody please help.

  6. thanks for this! learning linux command line scripts now after installing fedora in my nephew’s inspiron 1525, was wondering how to get to root user, other sites weren’t explaining well enough so again, thanks a million! :)

  7. Being a super user can be VERY dangerous so I suggest you know what your doing if your going to become a super user but another way to get root access is to type into the command line:

    sudo -i

    Still, have a question? Get help on our forum!