Secrets to Linux Server Security: Master These Essential Commands

WBOY
Release: 2023-09-09 17:34:43
Original
1030 people have browsed it

Secrets to Linux Server Security: Master These Essential Commands

Secrets to Linux server security: Master these must-have commands

Summary: Securing a Linux server requires a comprehensive approach that includes proficiency in the use of some must-have commands is very important. This article will introduce several commonly used Linux commands and provide code examples to help administrators improve server security.

  1. Firewall (Firewall)
    The firewall is the first line of defense to protect server security. In Linux, use the iptables command to configure firewall rules. The following are some commonly used iptables commands and their examples:

1.1 Enable firewall

sudo systemctl start iptables
Copy after login

1.2 Add rules

sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
sudo iptables -A INPUT -j DROP
Copy after login

1.3 View firewall rules

sudo iptables -L -n
Copy after login
  1. SSH login management
    SSH is a common tool for remote login between administrators and servers, and it is also a key point in server security. Here are a few ways to secure SSH:

2.1 Disable root remote login

sudo nano /etc/ssh/sshd_config
PermitRootLogin no
Copy after login

2.2 Use a key pair for authentication

ssh-keygen -t rsa
Copy after login

2.3 Change SSH Port

sudo nano /etc/ssh/sshd_config
Port 2222
Copy after login
  1. Fine-grained file permission control
    Properly configured file permissions can prevent unauthorized access and modification. The following are several commonly used commands:

3.1 Change file permissions

chmod 600 file.txt  # 只有所有者拥有读写权限
chmod 644 file.txt  # 所有者拥有读写权限,其他用户只读权限
chmod +x script.sh  # 添加可执行权限
Copy after login

3.2 Change file owner

sudo chown username:groupname file.txt
Copy after login
  1. Package Management
    Timely Updating software packages is key to keeping your server secure. The following is an example of using the apt command to manage packages:

4.1 Update package list

sudo apt update
Copy after login

4.2 Upgrade all installed packages

sudo apt upgrade
Copy after login

4.3 Search Specific software package

apt search package_name
Copy after login
  1. Log management
    Log files record various activities of the system, including security-related information. The following are some commonly used commands:

5.1 View system log

tail -f /var/log/syslog
Copy after login

5.2 View login log

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

5.3 View error log

tail -f /var/log/nginx/error.log
Copy after login

Comprehensive As mentioned above, proficient use of these necessary commands is the key to protecting the security of Linux servers. Administrators should regularly update software packages, configure firewall rules, restrict SSH access, and set file permissions correctly. At the same time, it is also very important to regularly audit system and login logs, as well as other security-related records. Armed with this knowledge, administrators will be better able to secure servers and improve system stability and performance.

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!