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

Sep 08, 2023 pm 01:46 PM
Command Line defense linux server

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Learn how to use the command line tool sxstrace.exe effectively Learn how to use the command line tool sxstrace.exe effectively Jan 04, 2024 pm 08:47 PM

Many friends who use win10 system have encountered this problem when playing games or installing the system. The application cannot be started because the parallel configuration of the application is incorrect. For more information, see the application event log, or use the command line sxstrace.exe tool. This may be because the operating system does not have corresponding permissions. Let’s take a look at the specific tutorial below. Tutorial on using the command line sxstrace.exe tool 1. This problem usually occurs when installing programs and games. The prompt is: The application cannot be started because the parallel configuration of the application is incorrect. For more information, see the application event log, or use the command line sxstrace.exe tool. 2. Start →

How to use PHP scripts to implement cross-server file transfer on Linux servers How to use PHP scripts to implement cross-server file transfer on Linux servers Oct 05, 2023 am 09:06 AM

Title: PHP script implementation of cross-server file transfer 1. Introduction In cross-server file transfer, we usually need to transfer files from one server to another. This article will introduce how to use PHP scripts to implement cross-server file transfer on Linux servers, and give specific code examples. 2. Preparation Before starting to write PHP scripts, we need to ensure that the following environment has been configured on the server: Install PHP: Install PHP on the Linux server and ensure that the PHP version meets the code requirements.

Upgrade Ubuntu 20.04 to 22.04 via command line Upgrade Ubuntu 20.04 to 22.04 via command line Mar 20, 2024 pm 01:25 PM

This article details the steps to upgrade Ubuntu 20.04 to 22.04. For users using Ubuntu 20.04, they have missed the new features and advantages brought by version 22.04. In order to get a better experience and security, it is recommended to upgrade to a newer Ubuntu version in time. Ubuntu22.04 is codenamed "Jamie Jellyfish", let's explore how to get the latest LTS version! How to upgrade Ubuntu 20.04 to 22.04 via the command line Mastering the command line will give you an advantage. While it is possible to update Ubuntu via the GUI, our focus will be via the command line. First, let’s check the currently running version of Ubuntu using the following command: $

How to deploy a trustworthy web interface on a Linux server? How to deploy a trustworthy web interface on a Linux server? Sep 09, 2023 pm 03:27 PM

How to deploy a trustworthy web interface on a Linux server? Introduction: In today's era of information explosion, Web applications have become one of the main ways for people to obtain information and communicate. In order to ensure user privacy and information reliability, we need to deploy a trustworthy Web interface on the Linux server. This article will introduce how to deploy a web interface in a Linux environment and provide relevant code examples. 1. Install and configure the Linux server. First, we need to prepare a Li

Detailed explanation of python command line parameters Detailed explanation of python command line parameters Dec 18, 2023 pm 04:13 PM

In Python, parameters can be passed to scripts via the command line. These parameters can be used inside scripts to perform different actions based on different inputs. Detailed explanation of Python command line parameters: 1. Positional parameters: parameters passed to the script in order on the command line. They can be accessed through position inside the script; 2. Command line options: parameters starting with - or -, usually Used to specify specific options or flags for the script; 3. Pass parameter values: Pass parameter values ​​through the command line.

A first look at Django: Create your first Django project using the command line A first look at Django: Create your first Django project using the command line Feb 19, 2024 am 09:56 AM

Start the journey of Django project: start from the command line and create your first Django project. Django is a powerful and flexible web application framework. It is based on Python and provides many tools and functions needed to develop web applications. This article will lead you to create your first Django project starting from the command line. Before starting, make sure you have Python and Django installed. Step 1: Create the project directory First, open the command line window and create a new directory

How to obtain the public IP address in the CentOS command line How to obtain the public IP address in the CentOS command line Jan 02, 2024 pm 10:28 PM

Recently, the server was configured locally, using home bandwidth without a fixed IP address. Therefore, you need to obtain your own public IP address. Since the machine is the server version of CentOS 6.5, there is naturally no way to obtain the public IP address through browser access. Therefore, some methods of obtaining public IP from the command line are recorded. First, you need to follow curl on your machine: [plain]viewplaincopysudoyuminstallcurl Second, use one of the following commands to get the local address: [html]viewplaincopycurlhttp://members.3322.org/dyndns/getipcurl

Linux server failure and security: How to manage your system healthily Linux server failure and security: How to manage your system healthily Sep 10, 2023 pm 04:02 PM

With the development of Internet technology, more and more enterprises and individuals choose to use Linux servers to host and manage their applications and websites. However, as the number of servers increases, server failures and security issues become an urgent task. This article will explore the causes of Linux server failures and how to manage and protect the system healthily. First, let's take a look at some common reasons that can cause Linux servers to malfunction. Firstly, hardware failure is one of the most common reasons. For example, the server is overheating,

See all articles