Home >Operation and Maintenance >Linux Operation and Maintenance >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.
Upgrade the system:
Run the following commands in the terminal to update and upgrade the system.
sudo apt-get update sudo apt-get upgrade
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.
Check the firewall status:
The following command will display the current firewall status.
sudo ufw status
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:
Create a new user:
The following command will create a new user.
sudo adduser <username>
Set password:
The following command will set the password of the specified user.
sudo passwd <username>
4. Disable root login:
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.
Restart the SSH service:
Use the following command to restart the SSH service.
sudo service ssh restart
5. Check the log file:
View login history:
The following command will display the recent user login history.
last
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!