Programster's Blog

Tutorials focusing on Linux, programming, and open-source

CentOS 7 - Disable Root Login

#!/bin/bash
SEARCH="#PermitRootLogin yes"
REPLACE="PermitRootLogin no"
FILEPATH="/etc/ssh/sshd_config"
sudo sed -i "s;$SEARCH;$REPLACE;" $FILEPATH
sudo service sshd restart

The script is exactly the same for debian users, except the last line in which you need to change sshd to ssh

Last updated: 29th July 2021
First published: 16th August 2018

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch