DEV Community

Cover image for How to disable root ssh login in Linux
Muhammad Ali Ahmed
Muhammad Ali Ahmed

Posted on

How to disable root ssh login in Linux

Before Getting Started

It is important to understand why it is important to disable root ssh login in Linux

Disabling direct SSH root login is a crucial security measure that helps protect your servers from unauthorized access and potential breaches. Root accounts have unrestricted access to the entire system, so if an attacker gains access to the root account, they can potentially control everything on the server. By disabling root SSH login, you enforce the use of lower-privileged accounts for remote access. Users must log in with their accounts and escalate privileges using sudo if necessary. This minimizes the risk and improves accountability, as each action can be traced back to a specific user rather than the all-powerful root.

You have to edit the sshd_config file

  1. Navigate to the /etc/ssh directory

    cd /etc/ssh

  2. Open the sshd_config file in a text editor

    nano sshd_config

    or

    vim sshd_config

  3. Edit the file

    Look for the line "PermitRootLogin"
    It may be commented out and its value can be yes, no, or
    prohibit-password. you have to uncomment it and write

     PermitRootLogin no
    
  4. Restart the ssh service

    sudo systemctl restart sshd

    The root ssh login will be disabled after the ssh service is
    restarted.

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay