Centos refused to remote ssh brute force method

Jiamusi SEO Summary

One day suddenly received a message, the message content to inform me of ECS server as a broiler attack other machines, at the beginning I thought, I must have a machine account password is compromised, or was brute force, Ever since, I inquired about the account login record my machine.

 

One day suddenly received a message, the message content to inform me of ECS server as a broiler attack other machines, at the beginning I thought, I must have a machine account password is compromised, or was brute force, Ever since, I inquired about the account login record my machine.

How to judge their own are suffering ssh brute force

Lastb use ssh command to use the root account login server, it will be displayed log of recent error log, including logs via ssh service error log.

image.png

If the result of the above and consistent content, a large number of output server that you are suffering from hackers brute force.

Here, Hainan SEO under teach you ways to prevent brute force

Method one: Modify ssh or ftp telnet port

Modify vim / etc / ssh / sshd_config file # comment in front of the Port will delete, and modify the 22 you want to use telnet port, such as 9999.

Adding to run ports at the firewall:
iptables the INPUT -p tcp - dport the -I 9999 -j ACCEPT

If you are using ubuntu system using ufw, you can use the command: sudo ufw allow 54231

If you use CentOS7 system and use firewalld, you can use the command:
Firewall-cmd = -zone public -add-Port = 54231 / tcp -permanent

If you are using the cloud server, cloud service providers have to provide external firewall, for example, in the case of Ali cloud security groups should increase to allow tcp port 54231 port policy in external security group.

The final restart sshd service can be used serivce sshd restart.

CentOS7 users systemctl restart sshd.

After the restart the service logon servers are required to enter the port to be able to specify the remote login server, greatly reducing the probability of hacking the server.

Method Two: Limit login IP

If your company or work network environment often need to log server has a fixed IP address, login IP address restrictions can be very good to protect the server from hacker attacks. If there is no such condition, we can also build a fortress machine, all servers are set to log on to protect your server to allow the fort's IP address.

Fairly simple operation, first add the following information in vim /etc/hosts.allow:

sshd:46.16.*.*

This information indicates that sshd service allows IP address to the IP address of the beginning of 46.16 to provide services.

Next add the following information in vim /etc/hosts.deny:

sshd:all:deny

This information represents sshd service is not allowed to provide services to all IP addresses.

In this way the server will only specified IP address can access.

Method three: Use non-root user login

Prohibit root user and allow other users to switch arranged to root login operation. If you want a hacker to log in via ssh server in addition to the password first of all he needs to know server allows users to log, which will greatly reduce the possibility of hacked ssh prohibit root account login is the most common kind of security policy, all large the company's servers are the root account is disabled

First, create a user in the server, useradd itwgy.com
and set a password: passwd itwgy.com, of course, need to try the password complex, contain characters, lowercase letters, numbers, as far as possible the length of greater than 15

Next we need to allow the user to run commands as root.
Use visudo command to enter a text editing mode, in the vicinity of the line 92

## Syntax:
##
## user MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
itwgy.com ALL=(ALL) NOPASSWD:ALL

Add red font information: "ALL = (ALL) NOPASSWD: ALL", save and exit can verify it.

[root@localhost ~]#visudo
[root@localhost ~]# su itwgy.com
[itwgy.com@localhost root]$ sudo su -
Last login: Tue May 22 12:55:36 CST 2018 on pts/1
[root@localhost ~]#whoami
root

The first to use su itwgy.com switch to itwgy.com user, then we can use the sudo su - command to switch to root user.

Similarly, we can also verify remote login using ssh client to the itwgy.com user login system, then using sudo su - command to switch.

In the settings after a user logs itwgy.com by the system and can freely switch to the administrator user, we need to ban the root user remotely log into the system.

Add in vim / etc / ssh / sshd_config file "PermitRootLogin no", restart sshd service, reboot command service sshd restart, after the start, root ssh service users will be connected directly to the server can not pass.

Source: Chengde SEO

Guess you like

Origin www.cnblogs.com/1994jinnan/p/11985669.html