Home > Operation and Maintenance > Linux Operation and Maintenance > The cornerstone of Linux server security: the use and configuration of important commands

The cornerstone of Linux server security: the use and configuration of important commands

WBOY
Release: 2023-09-08 14:21:19
Original
789 people have browsed it

The cornerstone of Linux server security: the use and configuration of important commands

The cornerstone of Linux server security: the use and configuration of important commands

In today's Internet era, data security is crucial. As a network administrator, protecting server security is our top priority. As an operating system widely used in server environments, Linux has powerful security functions and rich security tools. This article will introduce some important commands and configurations to help you better protect the security of your Linux server.

  1. View and manage user accounts

On the Linux server, we must first ensure the security of user accounts. Here are some common commands to view and manage user accounts:

  • View currently logged in users:

    whoami
    Copy after login
  • View all users on the system Account:

    cat /etc/passwd
    Copy after login
  • Create a new user account:

    sudo adduser username
    Copy after login
  • Change user password:

    sudo passwd username
    Copy after login
  • Delete User Account:

    sudo deluser username
    Copy after login
  1. Configure Firewall

Firewalls are an important part of protecting your server from unauthorized access. There are several firewall tools to choose from in Linux, the most commonly used and widely supported of which is iptables. Here are some common commands to configure the firewall:

  • View the current firewall rules:

    sudo iptables -L
    Copy after login
  • Allow or deny specific IP addresses or ports :

    sudo iptables -A INPUT -s IP_ADDRESS -p tcp --dport PORT -j ACCEPT
    sudo iptables -A INPUT -s IP_ADDRESS -p tcp --dport PORT -j DROP
    Copy after login
  • Saving and loading firewall rules:

    sudo iptables-save > /etc/iptables/rules.v4
    sudo iptables-restore < /etc/iptables/rules.v4
    Copy after login
  1. Updating and maintaining packages

Timely updating of software packages is one of the important measures to keep your server secure. Here are some commonly used commands to update and maintain packages:

  • Update package list:

    sudo apt update
    Copy after login
  • Update installed packages:

    sudo apt upgrade
    Copy after login
  • Regularly check and fix package dependency issues:

    sudo apt-get install -f
    Copy after login
  1. Configure SSH access

SSH (Secure Shell) is a secure remote login protocol. Here are some commonly used commands to configure SSH access:

  • Disable root user from logging in via SSH:

    sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/sshd_config
    sudo service ssh restart
    Copy after login
  • Use key to log in instead of password :

    ssh-keygen
    ssh-copy-id username@host
    Copy after login
  • Configure SSH session timeout:

    sudo sed -i 's/#ClientAliveInterval 0/ClientAliveInterval 60/' /etc/ssh/sshd_config
    sudo sed -i 's/#ClientAliveCountMax 3/ClientAliveCountMax 0/' /etc/ssh/sshd_config
    sudo service ssh restart
    Copy after login
  1. Monitor log file

Monitor server log It can help us detect and solve security problems in time. The following are some commonly used commands to monitor log files:

  • View system logs:

    sudo tail -f /var/log/syslog
    Copy after login
  • View authentication logs:

    sudo tail -f /var/log/auth.log
    Copy after login
  • View Apache access log:

    sudo tail -f /var/log/apache2/access.log
    Copy after login
  • View Nginx access log:

    sudo tail -f /var/log/nginx/access.log
    Copy after login

The above are just some Linux server security areas Examples of basic commands in . Of course, protecting server security involves more aspects, such as using secure network protocols, configuring hardware firewalls, and so on. However, being familiar with and using these basic commands and configurations correctly will provide you with a more secure Linux server environment.

The above is the detailed content of The cornerstone of Linux server security: the use and configuration of important commands. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template