Home >Operation and Maintenance >Linux Operation and Maintenance >Secrets to Linux Server Security: Master These Essential Commands

Secrets to Linux Server Security: Master These Essential Commands

PHPz
PHPzOriginal
2023-09-09 08:18:391302browse

Secrets to Linux Server Security: Master These Essential Commands

Secrets of Linux server security: Master these essential commands

Abstract:
With the development of the Internet, the security of Linux servers is becoming more and more important . This article will introduce some commonly used commands to help us improve the security of Linux servers.

1. Update the system and software:
Keeping the latest version of the system and software is one of the important steps to ensure the security of the server. Below are the commands to update your system and software.

  1. Upgrade the system:
    Run the following commands in the terminal to update and upgrade the system.

    sudo apt-get update
    sudo apt-get upgrade
  2. Update software:
    The following commands are used to update installed software packages.

    sudo apt-get update
    sudo apt-get dist-upgrade

2. Firewall configuration:
Firewall is an important tool to protect the server from intrusion. Below are some useful commands to configure the firewall.

  1. Check the firewall status:
    The following command will display the current firewall status.

    sudo ufw status
  2. Enable the firewall and set the rules:
    The following command will enable the firewall and set the allowed inbound and outbound rules.

    sudo ufw enable
    sudo ufw allow <port>

    For example, to allow SSH connections, you can run the following command.

    sudo ufw allow ssh

    3. Protect the user with a strong password:

  3. Create a new user:
    The following command will create a new user.

    sudo adduser <username>
  4. Set password:
    The following command will set the password of the specified user.

    sudo passwd <username>

    4. Disable root login:

  5. Modify the /etc/ssh/sshd_config file:
    Use the following command to open the sshd_config file.

    sudo nano /etc/ssh/sshd_config

    Find the following line:

    #PermitRootLogin yes

    Change it to:

    PermitRootLogin no

    Save and exit.

  6. Restart the SSH service:
    Use the following command to restart the SSH service.

    sudo service ssh restart

    5. Check the log file:

  7. View login history:
    The following command will display the recent user login history.

    last
  8. View system log:
    The following command will display the last few lines of the system log file.

    tail /var/log/syslog

    The above commands give some important commands and examples to improve the security of Linux servers. Mastering these commands can greatly improve the security of your Linux server. Keeping systems and software updated, configuring firewalls, setting strong passwords, disabling root logins, checking log files, etc. are all critical steps in protecting your server from attacks.

But please note that the commands mentioned in this article are only part of the methods to improve server security. In order to ensure server security, we also need to take other security measures, such as regularly backing up data, using SSL certificates to encrypt communications, restricting user permissions, etc.

We hope that the commands and examples introduced in this article can help readers improve the security of Linux servers and provide effective guidance for creating a secure network environment.

The above is the detailed content of Secrets to Linux Server Security: Master These Essential Commands. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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