• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

How To Disable Root Logins On Linux

Bhagwad Park

Published on: July 18, 2018

Categories: VPS Hosting 0

In the last tutorial, we saw how to give a user sudo privileges. One of the main benefits, is that we’re now free to disable root logins on Linux. So why is important?

Most Linux installations come with the root user by default. Ubuntu is one notable exception where root is disabled. The problem with the “root” user is that it can do everything, and isn’t linked to any particular user. It’s a sort of “catch-all” account that’s very dangerous in the wrong hands. Disabling root access has a lot of little benefits, none of which is persuasive enough by themselves. However taken together, they’re pretty convincing.

Here are a few benefits.

  1. Attacker Needs to Guess two pieces of information instead of just one – the username AND the password
  2. Users will need to specifically request admin permissions via the “sudo” command instead of having admin access by default
  3. It’s easy to audit user activities and find out which user performed which activity instead of merely having “root” as the user

There are other benefits as well, but these are some of the main ones. Like I said, there are arguments debating the efficacy of each of them, but together they form a pretty solid front. Disabling root logins is a good idea on general principles.

So here’s how we do it.

Step 1: Logging in as Root and Opening the sshd_config File

As you can see below, I can log in as root by default using SSH:

To disable root logins we need admin privileges to start with so we can modify the following file:

/etc/ssh/sshd_config

So either use your account’s “sudo” capability, or log in as root itself. Open the file in a text editor:

vi /etc/ssh/sshd_config

Step 2: Change One Line in sshd_config

Now scroll all the way down or search for the line that starts like this:

#PermitRootLogin yes

As shown here:

The hash character (#) indicates that the line has been “commented out”. So we’re going to make two changes:

  1. Remove the hash (#)
  2. Change “yes” to “no”

So the line will finally look like this:

PermitRootLogin no

Make these changes, and save the file. Once done, we need to restart the sshd service so that our changes will take effect. We do this using the following command:

systemctl restart sshd

Again, remember to use “sudo” before these commands if you don’t have admin privileges by default, or login as root to perform them. After this works, you won’t be able to log in again!

Step 3: Testing Your Changes

If you’ve done the previous steps properly, you should now be prevented from logging in as root. Since I tested it at the beginning of this, I perform the same test again:

This time, you can see that if I try and login as root directly, I get an “access” denied message. That’s great. Looks like we’ve successfully disabled root logins on Linux!

But What if you NEED Root Later On?

While you should be able to use “sudo” to perform admin actions instead of root, there might come a time when you realize you need root access after all. Don’t worry! Root hasn’t vanished. You can still access root from any other user by typing in the following command:

su - root

This will prompt you for the root password and log you into root as shown here:

So worst case scenario, it’s still available to you if you need it. In general, it’s a good idea to use it as infrequently as possible!

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Related Posts

How to Use Vim Search and Replace in Linux

The vim search and replace functionality in Linux consists of a series of very powerful tools - but also simple ones to get started easily.

Using Systemctl to Enable Services on Boot on Linux

You can use the systemctl tool to start services automatically on boot. We do this using the "enable" keyword.

Bash Debug Mode: set -x and the PS4 Variable

When coding a program, you usually have a full IDE set up with autocomplete and stack tracing, allowing you to pause execution at any point and see what’s going on under the hood. These tools make coding more productive, and they’ve been in use for a long time. But what if you’re just quickly coding […]

Using Bash Job Controls to Manage Multiple Processes

Bash job controls are used to send long running tasks into the background, and bring them forward when necessary.

Reader Interactions

Leave a Reply Cancel reply

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.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA