The command line is your defensive weapon: protect your Linux server
With the rapid development of computer technology, Linux servers have become the first choice for many enterprises and individuals. However, along with it comes an increase in cybersecurity threats. To protect our servers from hackers and malware, we need to utilize some powerful tools and techniques. The command line is one of our defensive weapons. This article will introduce some commonly used command line tools and techniques to help you protect your Linux server.
iptables is a very powerful firewall tool in Linux systems that can help us filter and manage network traffic. The following are some commonly used iptables commands:
iptables -L
iptables -A INPUT -p tcp --dport 80 -j ACCEPT iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT
iptables -A INPUT -s 192.168.1.100 -j DROP
iptables -A INPUT -p tcp --dport 22 -j DROP iptables -A OUTPUT -p tcp --sport 22 -j DROP
fail2ban is an automated IP blocking tool that automatically blocks malicious IP addresses based on the number of failed login attempts. We can install and configure fail2ban by following these steps:
sudo apt-get install fail2ban
sudo vi /etc/fail2ban/jail.local
In Add the following content at the end of the file:
[sshd] enabled = true port = 22 filter = sshd logpath = /var/log/auth.log maxretry = 3
sudo systemctl start fail2ban sudo systemctl enable fail2ban
sudo fail2ban-client status sshd
By configuring the SSH server, we can improve the security of the server. The following are some commonly used SSH configuration examples:
Edit the SSH configuration file:
sudo vi /etc/ssh/sshd_config
Find the following line and modify it to The port number you want (e.g. 2222):
#Port 22 Port 2222
Add the following line in the SSH configuration file:
PermitRootLogin no
Add the following line at the end of the SSH configuration file to only allow the specified IP address to access the SSH server:
AllowUsers user1@192.168.1.1 user2@192.168.1.2
sudo systemctl restart sshd
Weak passwords are a common target for hackers. To protect our servers, we should use strong password policies. Here are some tips for generating and using strong passwords:
It is important to keep systems and applications up to date as updates often include fixes for security vulnerabilities and enhancements patch. Use the following commands to update your system and applications:
sudo apt-get update sudo apt-get upgrade
sudo yum update
Summary:
Protecting your Linux server from hackers and malware is crucial. By using command line tools and techniques, we can enhance the security of our servers. Whether it's by configuring your firewall, using tools that automatically block malicious IPs, or improving your SSH configuration and using strong passwords, you can improve your server's security. Finally, regularly update systems and applications to ensure your servers always have the latest security patches.
The above is the detailed content of The command line is your defense: Protect your Linux server. For more information, please follow other related articles on the PHP Chinese website!