How Can I Log In As root User?

sudo command demo

How do I log in as root user under Linux, Apple OS X, *BSD, and UNIX-like operating systems?

On Linux, *BSD, and UNIX like opeating systems the root user act as a superuser. Root user is the conventional name of the user who has all rights or permissions on the system. The root user can do many things an ordinary user cannot, such as changing the ownership of files, mounting disk, formatting & restating new file system, starting/stopping services, and binding to ports numbered below 1024 and more.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements su/sudo
Est. reading time Less than a minute
It is not good a practice for anyone to use root as their normal user account, because of security risks. Therefore, you use a normal user account instead. You need to use the su or sudo command to switch to root user account.

su command

The su command is use to change user ID or become super-user during a login session i.e. it allows you to become a super user or substitute user, spoof user, set user or switch user.

Note: su only works if you know the target or root user’s password.

su command syntax

The syntax is:

su - {user-name}

If invoked without a user-name, su defaults to becoming the super user. The user will be prompted for a password, if appropriate.

To log in as root user type the following command (you need to supply root user account password when prompted):
$ su -
Sample outputs:

Password: *******

Once logged in, your prompt should change from $ to #. To log in as another user say nixcraft, type the following command (you need to supply nixcraft user account password when prompted):
$ su - nixcraft
Sample outputs:


Remote root login over the ssh session

You can use the ssh client as follows:
$ ssh root@server.ip-address-here
$ ssh
$ ssh root@

However, remote root login over ssh session is disabled in most cases for security reasons. First, login as a normal user and then switch to root account using the su command:

 ## login as a normal user ##
## now switch to root account ##
su -

su command and log files

The su command logs its usage in a system log file. This is useful to find out su login information. If you are RHEL / CentOS / Fedora Linux user type the following as root to see the contents of /var/log/secure:
# tail -f /var/log/secure
Debian / Ubuntu Linux user try:
# tail -f /var/log/auth.log
Sample outputs:

May 30 23:02:56 wks05 su[23520]: pam_authenticate: Authentication failure
May 30 23:02:56 wks05 su[23520]: FAILED su for root by nixcraft
May 30 23:02:56 wks05 su[23520]: - /dev/pts/3 nixcraft:root
May 30 23:02:59 wks05 su[23521]: pam_unix(su:auth): authentication failure; logname=nixcraft uid=1000 euid=0 tty=/dev/pts/3 ruser=nixcraft rhost=  user=root
May 30 23:03:01 wks05 su[23521]: pam_authenticate: Authentication failure
May 30 23:03:01 wks05 su[23521]: FAILED su for root by nixcraft
May 30 23:03:01 wks05 su[23521]: - /dev/pts/3 nixcraft:root

Say hello to sudo command

The sudo is a program for Linux / Apple OS X / *BSD / Unix-like computer operating systems that allows users to run programs with the security privileges of another user, normally the superuser (root). By default, sudo will prompt for a user password but it may be configured to require the root password or no password at all. Apple Mac OS X and Ubuntu Linux and many other oses uses sudo command for many administrative tasks.

sudo executes a command as another user but follows a set of rules about which users can execute which commands as which other users. This is configured in a filed named /etc/sudoers. Unlike su, sudo authenticates users against their own password rather than that of the target user. See how to configure and use sudo tool under Linux operating system.

For example, to login as root under Linux or Unix like operating system, type:
$ sudo -s

Sample sudo command session

Fig.01: Switching to root account using sudo command

Fig.01: Switching to root account using sudo command

Sudo and log file

The sudo log can be viewed by issuing the following command as root user:

## Generic file for Unix/Linux ##
tail -f /var/log/messages
## Debian/Ubuntu and friends ##
tail -f /var/log/auth.log
## RHEL/CentOS/SL/Fedora Linux ##
tail -f /var/log/auth.log

Sample outputs:

May 30 23:12:42 wks05 sudo: nixcraft : TTY=pts/3 ; PWD=/tmp ; USER=root ; COMMAND=/bin/bash
May 30 23:12:42 wks05 sudo: pam_unix(sudo:session): session opened for user root by nixcraft(uid=1000)
See also

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 30 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
30 comments… add one
  • John Webb Sep 9, 2007 @ 23:09

    I have installed ubuntu and always log in as user. I have read the HOW TOO’s but I am confused by the comment ‘Make sure you use the root password.’ How can you use a root password when you haven’t got one (I think) because the only password I use is the password I gave when I installed Ubuntu (dapper Drake). Is this a root password also if you say it’s root as time of login. If you have to have a seperate login root password – How do you get it? Thanks john6.

    • Naveen Kumar Jul 21, 2010 @ 9:51

      By default, the root account password is locked in Ubuntu. This means that you cannot login as root directly or use the su command to become the root user. However, since the root account physically exists it is still possible to run programs with root-level privileges.

      • Mark cope Mar 12, 2011 @ 4:39

        Hmmm, lets see Can not log in as : \ SU Thought Ubuntu is open source The only why you can adjust the Kernel is as root. what they hiddin willis.

        • Mark cope Mar 12, 2011 @ 4:42

          opp’s should have read more of the reply’s. but as a openBSD user never really had this issue.

  • Dr. Fak Sep 13, 2007 @ 19:38

    Thank you very much for this help!

    To all the latin people… is the answer in spanish:

    Escriban “su -” para cambiar al root. Les pedira la clave del root.

    Escriban “su – gon” para cambiar al usuario llamado gon. Les pedira la clave.

    Thanks again.


  • AIS Jan 17, 2009 @ 15:08

    You can change your root password by typing in console” sudo passwd root ” By doing this i had to enter my user password then set a new root password and repeat it.

    • Buck Feb 8, 2013 @ 1:40

      Baller. That was perfect. Thank you.

  • Kwame Apr 25, 2009 @ 14:27


  • fahim Jul 18, 2009 @ 3:37

    thnx. by default there is no password for root, hve to get by typing ”sudo passwd root”.

  • Riobe Aug 26, 2009 @ 18:29

    Thanks for this article and to AIS/fahim for the additional information about how to change the root password! Just what I was looking for.

  • Antonio Sep 6, 2009 @ 12:41

    AIS, thanks a lot

  • Gregory W Sep 6, 2009 @ 19:16

    The question is still unanswered.

    To login as root is very convenience and very important for some applications. Without it, you may not be able to run those programs at all. Su is good but with great limitation.

    So if anyone who know the answer, please help. We do not need advise about workaround.

  • Gregory W Sep 6, 2009 @ 20:09

    After 5 minutes of browsing on the Internet, I found it is very easy to make the changes so you can login as root from GUI. This is for Fedora 11:

    First, (dangerous?) you must su and login as root then cd to /etc/pam.d
    There are two files: gdm and gdm-password. Use your editor and
    Comment this statement for both files:

    # auth required user != root quiet

    Save and logout. Try login as root. You should be.

  • Gregory W Sep 9, 2009 @ 4:01

    After login as root and play around, I found the above changes were not enough. Thanks to, I found the last piece that fixed the problem.

    You need to edit another file: /etc/PolicyKit/PolicyKit.conf
    and add
    between .

    That will do the job.

  • Gregory W Sep 9, 2009 @ 4:22

    The missing statement between <config></config> is
    <match user=”root”><return result=”yes” /><match>

  • Asheesh Sep 23, 2009 @ 21:16

    Thanks a tonnnnn Gregory. Somehow I could never find the answer for this , instead of getting ridiculed for wanting this. :)

  • Vytautas Jun 5, 2011 @ 17:11

    Thanks for command “sudo passwd root” !!

  • person Feb 22, 2012 @ 9:40

    you didn’t answer the question!

    you condescendingly gave some “best practices” advice, and then proceeded to explain out how to do something else.

  • Newbe Mar 13, 2012 @ 2:06

    I have to agree that the entire tenor of this conversation is offensive. Crossing the street is dangerous, also, but I do it anyway. My mother taught me the risks when I was quite small, as well as how to do it safely. If you really want to keep UBUNTU safe from learning problems, I suggest that you lock down the entire system and send us all to a Windows app.

    Instead, please stop insulting all of us who are adults and capable of taking our own risks. I need to open the folder /etc/openvpn using my GUI and add a file to the folder. Stop patronizing me and tell me how to do this please.

  • McAuley Mar 21, 2012 @ 14:40

    I agree whole-heartedly. Uber-geek Linux users can be extremely condescending. I’ve had them to tell me to RTFM. Which one? The “right” one”? The “other” one. The one that applies to my distro? Oh wait, that distro has tons of bugs, but the upcoming distro gives you a workaround. RTFM!
    How bout this? FTFM ! FIX it. Fix all the crappy and conflicting documentation. Yeah, this thing is “free”. But when all the wasted time getting things to work is considered, it’s more expensive than products from The Dark Empire. Bottom line is, if you’re going to do something, whether it’s for free or not, do it right and make it work like you say it does. Or don’t do it at all.
    You people have a lot of nerve criticizing Windows when you worship a product that is a stone’s throw away from hieroglyphics and documented in glyphs.
    Cheers, ubers …

  • tonto Jul 12, 2012 @ 15:59

    I agree wholeheartedly. I need Linux for a project, but it, and all other Linux distros I’ve used, seems to be dwelling in the past, and the developers delight in their backward approach and to delight in making things difficult. Personally, I think it’s almost up to the Windows 98 point, but not quite there yet….

  • pankaj Aug 31, 2012 @ 4:28

    way of xplanation is right

  • Rathod Jul 27, 2013 @ 5:22

    tx for using this site

  • niloufar Sep 18, 2013 @ 7:44

    Thanks for your favor ,It wa so usefull

  • Arif May 13, 2014 @ 21:39


    I ran following commands as root and now im am unable to su from any user/admin please advise.

    chmod -o-x /bin/su
    chmod -g-x /bin/su

  • robert Oct 14, 2014 @ 20:04

    Linux has become more and more like microsoft, not allowing root log in? really?
    I thoguht the whole selling point for linux back in the day was that we didnt have the hood welded shut!! Any one remember that, I also remember that in the beginning of linux.. back when it was all terminal there was only root!! you could add other users of course, but why? Any way my point being is that with out Root LOG IN!! you are just anothe windows microsoft puppet.

  • Leo Leavitt Mar 22, 2015 @ 0:28

    I have read all of the notes on root login and still do not have the answer that i want. I have over 30 years in the business and since retired a 100% disabled Vet. I just want to be able to Login as root just like any other user and I do not want to have to su each time to do things. I am well aware of the risks but since this is my own Ubuntu System I think I am capable of managing it. I am running UBuntu 14.10 and what I would like is to be able to do the following;
    Login root
    passwrd lslslslslsl
    and then I will be root for anything that I need . Please help with a simple straight way to do this in UbunTu.. DO I need to use Fedora instead ??
    Leo Leavitt

  • Mashkoor Qadir Dec 2, 2016 @ 6:10

    Hi Team,

    I am having a problem since yesterday. A server was running since 2 years and every thing was working fine. suddenly yesterday it refused to accept the credentials. It doesn’t allow to login even with root user.

  • JOSÉ EUDES F DA S Jan 12, 2017 @ 23:23


  • Elmore Toppin Feb 10, 2017 @ 15:40


    I installed Ubuntu through VMware Fusion on a Mac, when the installation process completed. I was only given an option to create a root user and root password. This does not allow you to log onto the system. The question is how do you log onto Ubuntu with this root password. Or how do you log onto Ubuntu, to get to this root user when no other user credentials were created at installation.
    Kind regards

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum