Home Operation and Maintenance Linux Operation and Maintenance How to secure your Linux server from the command line

How to secure your Linux server from the command line

Sep 09, 2023 pm 07:54 PM
firewall ssh User rights

How to secure your Linux server from the command line

How to protect your Linux server through the command line

In today’s digital age, Linux servers have become the first choice for many businesses and individuals. However, as hackers and malware continue to evolve, it is even more important to protect your servers from attacks. While there are many server protection tools and firewalls to choose from, basic server protection via the command line is also a great approach. In this article, we will introduce some simple but effective command line methods to help you protect your Linux server.

  1. Use a firewall:

The first line of defense for a Linux server is the firewall. It helps you limit network traffic to and from your server. In most Linux distributions, you can use the iptables command to configure firewall rules.

The following are some commonly used iptables command examples:

1.1 Allow specific IP addresses or IP ranges to access the server:

$ iptables -A INPUT -s 192.168.1.100 -j ACCEPT
Copy after login

1.2 Allow traffic on specific ports:

$ iptables -A INPUT -p tcp --dport 22 -j ACCEPT
Copy after login

1.3 Deny all other traffic:

$ iptables -P INPUT DROP
Copy after login

Please note that the above are just some example commands, you may need to modify them accordingly based on your server configuration.

  1. Use login authentication:

To prevent unauthorized access, you should configure login authentication. This can be achieved by changing the SSH configuration file. You can use a text editor such as vi or nano to open the /etc/ssh/sshd_config file.

$ sudo vi /etc/ssh/sshd_config
Copy after login

Find the following line in the file, then uncomment and modify it to the following:

PermitRootLogin no
PasswordAuthentication no
Copy after login

Save and close the file. By disabling remote root login and password verification, you will increase your server security.

  1. Update servers and software regularly:

Keeping servers and software up to date is also one of the important steps to protect your server. Hackers often exploit known security holes to gain access to servers. To avoid this, you should regularly update the operating system and software packages on your server.

In Ubuntu or Debian system, you can use the following command to update:

$ sudo apt update
$ sudo apt upgrade -y
Copy after login

In CentOS or RHEL system, you can use the following command to update:

$ sudo yum update -y
Copy after login

Be sure to back up important files and configurations before updating.

  1. Install an Intrusion Detection System (IDS):

An intrusion detection system (IDS) can help you monitor and detect potential attacks in real time. It analyzes network traffic and log files on your server and warns you of possible intrusion activity. You can use the fail2ban tool to implement intrusion detection.

On most Linux distributions, you can install fail2ban using the following command:

$ sudo apt install fail2ban
Copy after login

Once fail2ban is installed, you can use the following Command to start it:

$ sudo service fail2ban start
Copy after login
  1. Monitor log files:

Regularly monitoring the server's log files is also one of the important steps to protect the server. You can use the tail command to view server log files in real time. For example, you can use the following command to monitor the /var/log/auth.log file:

$ sudo tail -f /var/log/auth.log
Copy after login

By monitoring log files, you can detect abnormal activities and potential attacks in a timely manner.

Summary:

By using the command line for basic server protection, you can effectively increase your server security. This article introduces several simple but effective methods, such as using firewalls, login authentication, regularly updating servers and software, installing intrusion detection systems, and monitoring log files. Of course, this is just the beginning, and you can further explore other server protection techniques and tools. Remember, protecting your server is an ongoing process and you need to stay vigilant and keep your security measures up to date.

The above is the detailed content of How to secure your Linux server from the command line. 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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Win11 firewall advanced settings gray solution Win11 firewall advanced settings gray solution Dec 24, 2023 pm 07:53 PM

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

How to enable or disable firewall on Alpine Linux? How to enable or disable firewall on Alpine Linux? Feb 21, 2024 pm 12:45 PM

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

How to remove the firewall logo on the Win10 desktop icon? How to remove the firewall logo on the Win10 desktop icon? Jan 01, 2024 pm 12:21 PM

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.

OpenSSH on Windows: Installation, Configuration, and Usage Guide OpenSSH on Windows: Installation, Configuration, and Usage Guide Mar 08, 2024 am 09:31 AM

For most Windows users, Remote Desktop Protocol (RDP) has always been the first choice for remote management because it provides a friendly graphical interface. However, for system administrators who require more granular control, SSH may better suit their needs. Through SSH, administrators can interact with remote devices through the command line, which can make management work more efficient. The advantage of SSH is its security and flexibility, making it easier for administrators to perform remote management and maintenance work, especially when dealing with a large number of devices or performing automated tasks. So while RDP excels in terms of user-friendliness, for system administrators, SSH is superior in terms of power and control. Previously, Windows users needed to borrow

How to fix UFW status showing as inactive in Linux How to fix UFW status showing as inactive in Linux Mar 20, 2024 pm 01:50 PM

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 if Edge browser is blocked by firewall? How to solve if Edge browser is blocked by firewall? Mar 13, 2024 pm 07:10 PM

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

Linux SSH login mutual trust configuration Linux SSH login mutual trust configuration Feb 19, 2024 pm 07:48 PM

1. The purpose of ssh mutual trust 1. SSH mutual trust is required when building a cluster, which is conducive to convenient operation on another node. 2. When using scp remote copy operation, you need to enter the user name and password of the target server. At this time, you can configure SSH mutual trust between Linux servers, so that you can log in without a password when operating between multiple Linux servers. 2. The principle of ssh mutual trust configuration. In short, the server stores the certificate of the target host so that authentication can be completed automatically without entering a password. 3. SSH mutual trust configuration steps 1. Each node generates its own public key and private key pair. 2. Send your public key file to the other party. 3. Verify whether the mutual trust configuration is successful. 4. Configure ssh mutual trust here with MYDB01 and

Win11 user permissions setting tutorial: How to configure Win11 user permissions Win11 user permissions setting tutorial: How to configure Win11 user permissions Jan 29, 2024 pm 08:33 PM

Some users will create multiple accounts when using computers, but some users' accounts do not have permissions, which means some operations cannot be performed directly? How to set user permissions in Win11? Users who are not sure can come to this site to see related strategies. How to set user permissions in Win11 1. Directly create the run function through the shortcut key combination [win+R], then enter [netplwiz] in the search box and click OK. 3. In the properties window that opens, click Group Members in the upper menu bar. 5. A window prompt will appear. Just click [Yes] to log out and restart the account to complete the settings.

See all articles