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

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.
- 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
1.2 Allow traffic on specific ports:
$ iptables -A INPUT -p tcp --dport 22 -j ACCEPT
1.3 Deny all other traffic:
$ iptables -P INPUT DROP
Please note that the above are just some example commands, you may need to modify them accordingly based on your server configuration.
- 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
Find the following line in the file, then uncomment and modify it to the following:
PermitRootLogin no PasswordAuthentication no
Save and close the file. By disabling remote root login and password verification, you will increase your server security.
- 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
In CentOS or RHEL system, you can use the following command to update:
$ sudo yum update -y
Be sure to back up important files and configurations before updating.
- 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
Once fail2ban is installed, you can use the following Command to start it:
$ sudo service fail2ban start
- 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
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!
Hot AI Tools
Undress AI Tool
Undress images for free
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undresser.AI Undress
AI-powered app for creating realistic nude photos
ArtGPT
AI image generator for creative art from text prompts.
Stock Market GPT
AI powered investment research for smarter decisions
Hot Article
Popular tool
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
20516
7
13629
4
Windows10 cannot connect to the Internet_Win10 network reset command detailed explanation
Jan 15, 2026 pm 03:27 PM
The Windows 10 "No Internet Access" problem can be solved through five methods: 1. Reset the network in settings; 2. Execute netsh in the command prompt to reset Winsock and IP protocol stack; 3. Uninstall and reinstall the network card driver in Device Manager; 4. Reset IPv4/IPv6 dual stack with PowerShell; 5. Disable and enable the network adapter.
Personal Income Tax Record Inquiry System Portal Personal Income Tax Payment Details Inquiry Official Portal
Jan 13, 2026 pm 06:27 PM
The official entrance to the personal income tax record inquiry system is https://etax.chinatax.gov.cn, which supports multiple secure login methods such as passwords, tax UKey scans, Alipay, WeChat, UnionPay Cloud QuickPass and other secure login methods. Full information such as comprehensive income for the past six years, special additional deductions, tax refund progress and tax payment reminders can be checked.
How to fix Win11 cannot modify time_Windows11 Windows Time startup
Jan 26, 2026 pm 12:21 PM
When manually modifying the system time in Windows 11 does not work, you need to perform a five-step repair in sequence: 1. Set the Windows Time service to automatic in services.msc and start it; 2. Turn off "Automatically set time" and "Automatically set time zone" in settings; 3. Pass gpedit.msc confirms that the account has the "Change System Time" permission; 4. Run the command prompt as an administrator and use the time and date commands to force the modification; 5. Release the UDP123 port and restart the service and execute w32tm/resync/force.
How to install Redis cluster on Linux_Linux distributed cache deployment solution [Advanced]
Feb 08, 2026 pm 07:39 PM
The Redis6 cluster must be created with redis-cli--cluster. It requires a minimum of 3 masters and 3 slaves, a total of 6 nodes. The client port and the corresponding cluster bus port (10000) must be opened. Correct configuration but blocked ports is a common cause of failure.
How to quickly complete the MySQL environment setup on Windows Windows database environment setup and service startup configuration
Feb 06, 2026 pm 07:40 PM
The MySQL service is not started or the command is unavailable. The main reason is that the service is not configured during installation, the data directory permissions are insufficient, my.ini is missing, or the authentication plug-in is incompatible. The service should be reconfigured, permissions and configuration files should be checked, and the root authentication method should be modified.
What are cross margin mode and isolated margin mode? Why is it easier for full positions to return to zero if they are not well controlled?
Jan 07, 2026 am 08:03 AM
In the cross-margin mode, the account is reset to zero due to the loss of a single position, which causes the margin pool to shrink, causing the liquidation price of all positions to move up and chain liquidation; in the isolated position mode, risk isolation is achieved through independent margins, and the maximum loss of a single position is locked in the initial margin.
What should I do if the PCL2 launcher cannot connect to the server?
Dec 30, 2025 pm 11:27 PM
When encountering the problem that the PCL2 launcher cannot connect to the server, there is no need to worry too much. You can refer to the following steps to troubleshoot and fix it. To confirm the local network status, you first need to verify whether the current device's network is in a normal and available state. Testing can be done by visiting popular websites or using other Internet applications. If there is a network disconnection (such as router abnormality, broadband arrears, Wi-Fi signal interruption, etc.), it will directly cause the PCL2 launcher to be unable to establish communication with the remote server. It is recommended to try restarting the router, reconnecting to Wi-Fi, or contacting the operator to confirm whether the network service is normal. Querying the server running status The server may be in the state of planned maintenance, sudden failure, or excessive load, thus temporarily rejecting external connection requests. Please go to the PCL2 official website
How to set up a shared printer on a Windows 10 computer_Win10 network discovery sharing
Jan 30, 2026 pm 02:24 PM
The problem stems from the fact that network discovery is not enabled or the sharing configuration is incomplete. You need to check that the same LAN and the dedicated network, driver and printer status, and workgroup are consistent; enable network discovery and file printer sharing; set the printer share name (pure English numbers); release the firewall SMB port; change the group policy to the classic authentication model; disable Guest and create a dedicated local account to authorize printing.




