4 Ways to Disable Root Account in Linux

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

9 Responses

  1. ROMSAT says:

    In my opinion it is bad practice to edit /etc/passwd, /etc/group or /etc/shadow directly; either use appropriate utilities such as usermod, or use the vipw special editor to do so as it is careful about file locking, data corruption, etc.

    Therefore, in the first method I recommend to do it so:

    # usermod -s /sbin/nologin root
    

    And I have a question: Where is the /etc/nologin.txt file in Ubuntu?… I can’t find it anywhere? Have I to create it?

    Thanks for all,
    Romsat.

    • Aaron Kili says:

      @ROMSAT

      Thanks for sharing your concern. This is true, it’s much better to use the mentioned utility for editing the files in question. And if the /etc/nologin.txt file doesn’t exist in Ubuntu, you can create it. Thanks for the feedback.

  2. Darren says:

    Looks like copy and paste error ( that to me = the same file + command)

    $ sudo vim /etc/pam.d/login
    OR
    $ sudo vim /etc/pam.d/login
    
  3. Jonix says:

    The file /etc/nologin.txt will also disable network logins, maybe not desirable.

    • Aaron Kili says:

      @Jonix

      It’s in fact the nologin program used to disable user login. The /etc/nologin.txt file if exists, stores a message which nologin displays to a user instead of the default message.

  4. JIm says:

    Most Linux OS’s today come with sudo rights installed and the root account already locked. A better tutorial would be how to unlock and relock the root account, if you need to do that.

  5. Bouzeghoub Redouane says:

    Thank you so much for this excellent article, it is really useful for those who want to disable root login in Linux.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.