Home > Article > Operation and Maintenance > 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.1 Enable firewall
sudo systemctl start iptables
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
1.3 View firewall rules
sudo iptables -L -n
2.1 Disable root remote login
sudo nano /etc/ssh/sshd_config PermitRootLogin no
2.2 Use a key pair for authentication
ssh-keygen -t rsa
2.3 Change SSH Port
sudo nano /etc/ssh/sshd_config Port 2222
3.1 Change file permissions
chmod 600 file.txt # 只有所有者拥有读写权限 chmod 644 file.txt # 所有者拥有读写权限,其他用户只读权限 chmod +x script.sh # 添加可执行权限
3.2 Change file owner
sudo chown username:groupname file.txt
4.1 Update package list
sudo apt update
4.2 Upgrade all installed packages
sudo apt upgrade
4.3 Search Specific software package
apt search package_name
5.1 View system log
tail -f /var/log/syslog
5.2 View login log
tail -f /var/log/auth.log
5.3 View error log
tail -f /var/log/nginx/error.log
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!