• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

securitywing

How to Disable Root Login Via SSH in Linux

by wing

Having the option of logging in to your server with SSH is essential for some web administrators, but logging in your server with root credentials via SSH is always unsafe. By the word root credentials, I mean that you should not remotely login with your server with root user name, rather use a less privileged user to login to your server and then use the “su” command to login as a root user.

So, the purpose of this post is to show you:

  • How to disable SSH with root username?
  • How to enable a normal user to login with SSH?
  • How to use root username after login with less privilege user name?

how to disable root user access via SSH in centos

Step 1

If you have already installed your Linux server, you need to make sure that you have created a user with password. For example, you want to create a username  chris, use the following commands:

#useradd chris
#passwd chris

Next type the password for the username chris.

When you type the above command a directory for the username will be created. If you want to delete a user name, type the following command:

#userdel –r username

Step 2

Now that you have a user other than the root user. So, you can safely deny the root user to access your server via SSH. To disable ssh root login you have to go to the following file:

Vi  /etc/ssh/sshd_config

sshd_config file

And then remove # from the line permitrootlogin. In vi editor, you need to press ”i” to enter in the insert mode. Then, use the backspace to remove the hash from the permitrootlogin and write no, instead of yes. After editing, your line should look like the following:

Permitrootlogin no

ssh root login disable i

To save the changes press “w”. use the ESC key to go back to the command mode in the vi editor. Finally, use type :quit to go back to our shell prompt.

Step 3

Now, restart sshd with the following command:

service sshd restart

The steps described above prevent Linux root login via SSH. Preventing SSH root login improves Linux security and considered top priority when IT security auditor assess Linux for security vulnerabilities.

Related posts:

  1. Linux Security Basics
  2. How to Create SSH key login with PuTTY in Windows
  3. Access Control List Configuration on Cisco Router
  4. Acunetix Web Vulnerability Scanner to Detect your Website’s Security Loopholes

Filed Under: Network Security Tips Tagged With: linux, putty, root login, ssh

Primary Sidebar

Please help us sharing

Categories

  • AWS
  • Basics
  • Containers
  • Cryptocurrency
  • Cyber
  • Internet Security and Safety
  • IS Audit
  • IT Security Exams
  • Law & Human Rights
  • Network Security Tips
  • Off Track
  • Social Media Governance
  • Tech Comparisons
  • Tech Stack Suitability
  • Telecom
  • Tutorial

CISSP Sample Test

Take a CISSP Sample Test

CISA Sample Test

CISA IT governance Sample test

Please Follow Us

Contact us for Ads

Go to Contact Form

Search

Footer

Copyrights

Protected by Copyscape Duplicate Content Detection Software

Securitywing.com reserves the copyrights of all of its published articles.No contents of this site is permitted to be published to anywhere else in the Internet.If any contents are found in any other websites, securitywing reserves the rights to file a DMCA complaint. But you have the right to use the link of any relevant article of this site to point from your website if you consider that it might improve the quality of your article.

Tags

audit AWS backup basics browser check cisco cloud computer configuration cyber data database email gmail hsrp ids iis informaiton internet kubernetes linux load balancing malware microsoft network protection redundancy risk router security security tips server social media SSL switch test tools vpn vrrp web webserver website windows wordpress

Copyright © 2010-2025 ·All Rights Reserved · SecurityWing.com