


How to protect your Linux server with command line tools
How to protect your Linux server through command line tools
The security of Linux servers is crucial, and they often host important applications and data. In many cases, command line tools are a simple and efficient way to protect your Linux servers. This article will introduce some commonly used command line tools and provide code examples to help you protect your Linux server.
- Use iptables for firewall configuration
iptables is a command line tool for configuring firewalls on Linux servers. You can protect your server from malicious traffic by allowing or denying specific network connections.
The following are some commonly used iptables command examples:
- Allow access to specific IP addresses
iptables -A INPUT -s 192.168.0.1 -j ACCEPT
- Deny access to specific IP addresses
iptables -A INPUT -s 192.168.0.2 -j DROP
- Allow access to specific ports
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
- Deny access to specific ports
iptables -A INPUT -p tcp --dport 23 -j DROP
- Use fail2ban For intrusion detection and prevention
fail2ban is a tool for detecting and blocking malicious IP addresses. It can monitor login attempts and block logins from malicious IPs via iptables.
The following is an example of how to use fail2ban to configure protected SSH:
- Install fail2ban
sudo apt-get install fail2ban
- Edit fail2ban’s configuration file
sudo vi /etc/fail2ban/jail.conf
- Open the configuration of SSH protection
[sshd] enabled = true port = ssh filter = sshd logpath = /var/log/auth.log maxretry = 3
- Start the fail2ban service
sudo systemctl start fail2ban
- Use ssh-keygen to generate the SSH password Key
Using SSH keys as a method of authentication is more secure than using passwords. You can use the ssh-keygen command to generate a pair of keys: a private key and a public key. Deploy the public key to the server and save the private key locally.
- Generate SSH key pair
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
- Copy the public key to the server
ssh-copy-id -i ~/.ssh/id_rsa.pub user@server
Now, you can use the private key key to authenticate via SSH without entering a password.
- Create basic authentication using htpasswd
If you want only specific users to be able to access your website or application, you can use the htpasswd tool to create basic authentication.
- Install apache2-utils (including htpasswd)
sudo apt-get install apache2-utils
- Create a user
sudo htpasswd -c /etc/apache2/.htpasswd user1
- Place the .htpasswd file Associated with the directory or application you want to protect.
This way, only users with a valid username and password can access the directory or application.
Summary
By using command line tools to protect your Linux server, you can enhance its security. This article introduces some commonly used command line tools, including iptables, fail2ban, ssh-keygen and htpasswd. By properly configuring and using these tools, you can effectively protect your server from malicious attacks and unauthorized access.
Remember that good security practices are an ongoing process and you should update your servers frequently and check and review security settings regularly.
The above is the detailed content of How to protect your Linux server with command line tools. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



When setting up the firewall, many friends found that their win11 firewall advanced settings were grayed out and unable to be clicked. This may be caused by not adding a control unit, or by not opening the advanced settings in the correct way. Let’s take a look at how to solve it. Win11 firewall advanced settings gray method one: 1. First, click the start menu below, search and open "Control Panel" at the top 2. Then open "Windows Defender Firewall" 3. After entering, you can open "Advanced Settings" in the left column . Method 2: 1. If the above method cannot be opened, you can right-click "Start Menu" and open "Run" 2. Then enter "mmc" and press Enter to confirm opening. 3. After opening, click on the upper left

On AlpineLinux, you can use the iptables tool to configure and manage firewall rules. Here are the basic steps to enable or disable the firewall on AlpineLinux: Check the firewall status: sudoiptables -L If the output shows rules (for example, there are some INPUT, OUTPUT, or FORWARD rules), the firewall is enabled. If the output is empty, the firewall is currently disabled. Enable firewall: sudoiptables-PINPUTACCEPTsudoiptables-POUTPUTACCEPTsudoiptables-PFORWARDAC

Many friends who use win10 system find that there is a firewall logo on the icon on the computer desktop. What is going on? This makes many friends with obsessive-compulsive disorder particularly uncomfortable. In fact, we only need to open the control panel and click " It can be solved by changing "Change User Account Control Settings". Let's take a look at the specific tutorial. How to cancel the firewall logo on the desktop icon in Windows 10 1. First, right-click the Start menu button next to the computer startup screen, and then select the Control Panel function from the pop-up menu. 2. Then select the "User Account" option and select the "Change User Account Control Settings" item from the new interface that appears. 3. After adjusting the slider in the window to the bottom, click Confirm to exit.

UFW, also known as Uncomplex Firewall, is adopted by many Linux distributions as their firewall system. UFW is designed to make it easy for novice users to manage firewall settings through both the command line interface and the graphical user interface. A UFW firewall is a system that monitors network traffic according to set rules to protect the network from network sniffing and other attacks. If you have UFW installed on your Linux system but its status shows as inactive, there could be several reasons. In this guide, I will share how to resolve the UFW firewall inactive issue on Linux systems. Why UFW Shows Inactive Status on Linux Why UFW Is Inactive by Default on Linux How to Inactive on Linux

How to solve the problem that the Edge browser is blocked by the firewall? Edge browser is Microsoft's own browser. Some users found that this browser was blocked by the firewall during use. So what's going on? Let this site give users a detailed introduction on how to recover the Edge browser if it is blocked by the firewall. How to restore the Edge browser if it is blocked by the firewall? 1. Check the firewall settings: - Click the "Start" button on the Windows taskbar, and then open "Settings". -In the Settings window, select Update & Security. -exist

How to use Vue for permission management and access control In modern web applications, permission management and access control is a critical feature. As a popular JavaScript framework, Vue provides a simple and flexible way to implement permission management and access control. This article will introduce how to use Vue to implement basic permission management and access control functions, and attach code examples. Defining Roles and Permissions Before you begin, you first need to define the roles and permissions in your application. A role is a specific set of permissions, and

While the concept behind the Snipping Tool in Windows 11 is great, one of its main features, recording video, is really disappointing. The screen recording feature is still relatively new, so it can be hard to get by with glitches. Nonetheless, let's take a look at the problem and try to find a solution. So why doesn’t the screenshot tool’s video recording function work? You may not have the latest version of Windows 11 installed. The snipping tool may be corrupted or corrupted. Third-party software such as antivirus software may prevent it from recording your screen. Your computer does not have enough RAM or hard drive space to store the screen recording. Viruses or malware on your computer interfere with the way programs work. How to get Snipping Tool to record my screen in Windows 11

Due to compatibility issues, some friends may need to uninstall Comodo Firewall, but they cannot delete it no matter how hard they try. Even if they are uninstalled using the uninstall tool, they will only uninstall the registry, but the files are still there, so we can do this. First we open it with win+R, then deactivate the services inside, and then we just delete the folder. How to uninstall comodo firewall: 1. First we open win+R2, then we enter services.msc3, then we find the Windows Management Instrumentation service 4, then we right-click to stop 5, then we delete C:\WINDOWS\system32\
