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