Home Operation and Maintenance Linux Operation and Maintenance Linux Server Security: Use Commands to Protect Your System

Linux Server Security: Use Commands to Protect Your System

Sep 08, 2023 am 10:42 AM
linux server Safety

Linux Server Security: Use Commands to Protect Your System

Linux Server Security: Use Commands to Protect Your System

Overview:

In the modern Internet era, server security has become a vital topic . For servers using the Linux operating system, there are many powerful commands that can help us protect system security. This article will introduce some commonly used commands to help you improve the security of your Linux server.

  1. Protect your server with a firewall

A firewall is the primary tool for protecting your server from unauthorized access. In Linux, we can use the iptables command to configure and manage firewall rules. Here are some examples of commonly used iptables commands:

  • View current firewall rules:
iptables -L
Copy after login
  • Allow a specific IP to access port 80:
iptables -A INPUT -p tcp --dport 80 -s 192.168.0.1 -j ACCEPT
Copy after login
  • Block specific IPs from accessing port 22 (SSH):
iptables -A INPUT -p tcp --dport 22 -s 192.168.0.2 -j DROP
Copy after login

The above commands are just a few examples, you can customize more complex firewall rules according to your needs.

  1. Use fail2ban to defend against brute force cracking

Brute force cracking is one of the common attack methods used by hackers. To prevent brute force attacks, we can use fail2ban to monitor login attempts and automatically block malicious IPs. Here are example commands to install and configure fail2ban on Ubuntu:

  • Install fail2ban:
sudo apt-get update
sudo apt-get install fail2ban
Copy after login
  • Create a custom configuration file:
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
Copy after login
  • Edit the configuration file (for example, change bantime to 3600):
sudo nano /etc/fail2ban/jail.local
Copy after login
  • Start the fail2ban service:
sudo systemctl start fail2ban
sudo systemctl enable fail2ban
sudo systemctl status fail2ban
Copy after login

Go through the above steps , fail2ban will automatically monitor SSH login attempts, and if malicious behavior is detected, it will automatically block the IP for a period of time.

  1. Use SSH key login instead of password login

Using SSH key login can improve the security of the server, because the key is much harder to crack than the password. Here is a simple example of logging in using an SSH key:

  • Generate SSH key:
ssh-keygen -t rsa
Copy after login
  • Copy the public key to the server:
ssh-copy-id username@your_server_ip
Copy after login
  • Modify the SSH configuration file to disable password login:
sudo nano /etc/ssh/sshd_config
Copy after login

Find PasswordAuthentication in the file and modify it to no.

  • Restart the SSH service:
sudo systemctl restart sshd
Copy after login

Now you can log in using your SSH key without entering a password.

  1. Update operating system and software packages

Regularly updating the operating system and software packages is a critical step in maintaining server security. With updates, you get the latest security fixes, as well as new features and improvements. Here is a sample command to update the Ubuntu operating system and packages:

  • Update package list:
sudo apt-get update
Copy after login
  • Update installed packages:
sudo apt-get upgrade
Copy after login
  • Update operating system version:
sudo apt-get dist-upgrade
Copy after login
  1. Back up important data regularly

Last but not least, backup regularly Important data on the server. Backups can help you recover your data and reduce losses in the event of a hacker attack, hardware failure, or other problem. You can use the rsync command to synchronize data to a remote server or external storage device. The following is a simple rsync command example:

rsync -avz /path/to/source username@remote_server:/path/to/destination
Copy after login

With the above command, you can copy the contents of the source directory to a remote server or a specified target location.

Conclusion:

Securing a Linux server is an important and evolving task. In this article, we introduce some commonly used commands and examples that can help you improve the security of your server. However, server security relies on more than just commands and configuration, and requires ongoing monitoring and updates. Please make sure to take other necessary security measures when protecting your server and stay current on security best practices.

(Note: The above example commands are applicable to Ubuntu operating system, other Linux distributions may be different)

The above is the detailed content of Linux Server Security: Use Commands to Protect Your System. 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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 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)

Android TV Box gets unofficial Ubuntu 24.04 upgrade Android TV Box gets unofficial Ubuntu 24.04 upgrade Sep 05, 2024 am 06:33 AM

For many users, hacking an Android TV box sounds daunting. However, developer Murray R. Van Luyn faced the challenge of looking for suitable alternatives to the Raspberry Pi during the Broadcom chip shortage. His collaborative efforts with the Armbia

deepseek web version entrance deepseek official website entrance deepseek web version entrance deepseek official website entrance Feb 19, 2025 pm 04:54 PM

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

How to install deepseek How to install deepseek Feb 19, 2025 pm 05:48 PM

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

BitPie Bitpie wallet app download address BitPie Bitpie wallet app download address Sep 10, 2024 pm 12:10 PM

How to download BitPie Bitpie Wallet App? The steps are as follows: Search for "BitPie Bitpie Wallet" in the AppStore (Apple devices) or Google Play Store (Android devices). Click the "Get" or "Install" button to download the app. For the computer version, visit the official BitPie wallet website and download the corresponding software package.

BITGet official website installation (2025 beginner's guide) BITGet official website installation (2025 beginner's guide) Feb 21, 2025 pm 08:42 PM

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

Zabbix 3.4 Source code compilation installation Zabbix 3.4 Source code compilation installation Sep 04, 2024 am 07:32 AM

1. Installation environment (Hyper-V virtual machine): $hostnamectlStatichostname:localhost.localdomainIconname:computer-vmChassis:vmMachineID:renwoles1d8743989a40cb81db696400BootID:renwoles272f4aa59935dcdd0d456501Virtualization:microsoftOperatingSystem:CentOS Linux7(Core)CPEOSName:cpe:

Ouyi okx installation package is directly included Ouyi okx installation package is directly included Feb 21, 2025 pm 08:00 PM

Ouyi OKX, the world's leading digital asset exchange, has now launched an official installation package to provide a safe and convenient trading experience. The OKX installation package of Ouyi does not need to be accessed through a browser. It can directly install independent applications on the device, creating a stable and efficient trading platform for users. The installation process is simple and easy to understand. Users only need to download the latest version of the installation package and follow the prompts to complete the installation step by step.

Get the gate.io installation package for free Get the gate.io installation package for free Feb 21, 2025 pm 08:21 PM

Gate.io is a popular cryptocurrency exchange that users can use by downloading its installation package and installing it on their devices. The steps to obtain the installation package are as follows: Visit the official website of Gate.io, click "Download", select the corresponding operating system (Windows, Mac or Linux), and download the installation package to your computer. It is recommended to temporarily disable antivirus software or firewall during installation to ensure smooth installation. After completion, the user needs to create a Gate.io account to start using it.

See all articles