Home > Operation and Maintenance > Linux Operation and Maintenance > The command line is your defense: Protect your Linux server

The command line is your defense: Protect your Linux server

WBOY
Release: 2023-09-08 13:46:42
Original
606 people have browsed it

The command line is your defense: Protect your Linux server

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.

  1. iptables: A powerful firewall tool

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:

  • View the current iptables rules:
iptables -L
Copy after login
  • Allow entry and exit of specific ports:
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT
Copy after login
  • Ban access from a specific IP address:
iptables -A INPUT -s 192.168.1.100 -j DROP
Copy after login
  • Block all entry and exit from a specific port:
iptables -A INPUT -p tcp --dport 22 -j DROP
iptables -A OUTPUT -p tcp --sport 22 -j DROP
Copy after login
  1. fail2ban : Automatically block malicious IPs

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:

  • Install fail2ban:
sudo apt-get install fail2ban
Copy after login
  • Edit configuration file:
sudo vi /etc/fail2ban/jail.local
Copy after login

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
Copy after login
  • Start the fail2ban service:
sudo systemctl start fail2ban
sudo systemctl enable fail2ban
Copy after login
  • Verify whether it takes effect:
sudo fail2ban-client status sshd
Copy after login
  1. SSH configuration: Increase security

By configuring the SSH server, we can improve the security of the server. The following are some commonly used SSH configuration examples:

  • Modify the SSH default port:

Edit the SSH configuration file:

sudo vi /etc/ssh/sshd_config
Copy after login

Find the following line and modify it to The port number you want (e.g. 2222):

#Port 22
Port 2222
Copy after login
  • Disable root remote login:

Add the following line in the SSH configuration file:

PermitRootLogin no
Copy after login
  • Configure SSH access restrictions:

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
Copy after login
  • Restart SSH Server:
sudo systemctl restart sshd
Copy after login
  1. Use Strong Passwords: Increase Account Security

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:

  • Use long passwords that contain uppercase and lowercase letters, numbers, and special characters.
  • Use a password management tool like KeePassXC or LastPass to generate and store complex passwords.
  • Change your password regularly and avoid reusing the same password across multiple websites and services.
  1. Update systems and applications regularly

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:

  • Ubuntu/Debian systems:
sudo apt-get update
sudo apt-get upgrade
Copy after login
  • CentOS/RHEL systems:
sudo yum update
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template