Prohibit root ssh logon to shell scripts in Centos

Source: Internet
Author: User
Tags ssh centos

Linux prohibits root users from logging on through ssh

Root users are prohibited from logging on through ssh by operating the sshd_config configuration file.
1. Open the ssh configuration file
Vim/etc/ssh/sshd_config
2. Find the following line of text in the file.
# PermitRootLogin no may also be # PermitRootLogin yes
3. Remove the # sign before the row and make it as follows:
PermitRootLogin no
4. Restart the ssh service.
/Etc/init. d/sshd restart
Next, try to log on with the root account and find that login is denied. Then, log on with a common user. If a common user needs root permissions to log on, he or she can use the su-command to switch to the root account.
If there are many common users in the machine, and we do not want all users to log on through shh, we can also achieve this through sshd_config configuration.
Open the sshd_config file and add the following line of text at the end of the file. aaa and bbb are users allowed to log on via ssh.
AllowUsers aaa bbb

Centos disables root ssh login scripts

Today I have time to organize another script.

#! /Bin/bash
 
SSH_ROOT_NO = 'awk'/PermitRootLogin/'/etc/ssh/sshd_config | awk
 
'{If ($1 = "'permitrootlogin'") print $1, $2 }''
 
SSH_ROOT_YES = 'awk'/PermitRootLogin/'/etc/ssh/sshd_config | awk
 
'{If ($1 = "# PermitRootLogin") print $1, $2 }''
 
If
 
["$ SSH_ROOT_YES" = "# PermitRootLogin yes"]
 
Then
 
Sed-I "s/# PermitRootLogin yes/PermitRootLogin no/g"/etc/ssh/sshd_config &&
 
Echo "set deny root to ssh ......"&&
 
Service sshd restart
 
Elif
 
["$ SSH_ROOT_NO" = "PermitRootLogin no"]
 
Then
 
Echo "ssh for root is already deny, nothing to do ......"
 
Fi

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.