How to log in as root in linux shell?

62,307

Solution 1

The correct way to login as root is to type:

su -

This works on systems where sudo is inavailable or not configured.

Some distributions disallow logging in as root and then one should run his commands like this:

sudo MyCommandHere...

Solution 2

I'd comment on sagar's answer if I could, as I wish to add that while

sudo -i

will log you in as root in the shell, it will move you to its home directory (/root) as well.

Edit: As said by Andreas,

sudo -s

would instead allow you to remain in your current directory, which may be useful.

Solution 3

use sudo -i command and put your current user password

Share:
62,307

Related videos on Youtube

Tamara Wijsman
Author by

Tamara Wijsman

In my free time I visit Stack Exchange to help out people with their questions and help maintain the community. Located in Belgium, I have studied Computer Science at the University of Antwerp and became a Master in Software Engineering. When I think a post can be improved I will try to do so by fixing grammatical or spelling errors, clarifying meaning without changing it, correcting minor mistakes, adding related resources or links. For the less obvious things of those I will leave a note in the edit, click on the date to see this. I will only edit content in posts once, and let the author or other users be free to choose to rollback; when there are opposing views, we can raise this to meta to let the majority decide which revision of the post they want. This will be done with respect of the original author and when I'm sure enough that it would only improve the post. Have a nice day! :)

Updated on September 17, 2022

Comments

  • Tamara Wijsman
    Tamara Wijsman over 1 year

    How to login as root in linux shell?

  • Andreas
    Andreas almost 14 years
    you could also use sudo -s
  • Jim Perrin
    Jim Perrin almost 14 years
    If you need to run a lot of commands as root but are forced to use sudo, sudo -s will get you a root shell too.
  • kiltek
    kiltek almost 5 years
    How to use this together with the-S flag in this fashion: echo "mypassword" | sudo -Si? Its not working and telling me -bash: line 1: mypassword: command not found.