Linux server security configuration

Source: Internet
Author: User
Part 1: RedHatLinux & nbsp; 1. overview & nbsp; Linux server version: RedHatLinuxAS & nbsp; for open operating systems-Linux, system Security settings include minimizing system services, restricting remote access, hiding important information, fixing security vulnerabilities, and using security tools

Part 1: RedHat Linux
1. Overview
Linux server version: RedHat Linux
For an open operating system-Linux, system security settings include minimizing system services, restricting remote access, hiding important information, fixing security vulnerabilities, using security tools, and regular security checks. This article focuses on user settings, how to enable services, system optimization, and other aspects of the system's security configuration, in order to make the Linux server more secure and stable.
2. user management
In Linux, a user account is a user's identity sign, which consists of a user name and a user password. The system stores the entered user name in the/etc/passwd file, and the entered password is encrypted in the/etc/shadow file. Under normal circumstances, these passwords and other information are protected by the operating system. only root users and operating system applications can access these passwords. However, this information can be obtained by common users if it is improperly configured or when system operation errors occur. Then, malicious users can use a type of tool called "password cracking" to obtain the pre-encryption password.
2.1 delete special user accounts and group accounts in the system:
# Userdel username
Userdel adm
Userdel lp
Userdel sync
Userdel shutdown
Userdel halt
Userdel news
Userdel uuucp
Userdel operator
Userdel games
Userdel gopher

The deleted users are created by default by the system, but some accounts are not used in common servers. However, these accounts are often used and attacked by hackers.
# Groupdel username
Groupdel adm
Groupdel lp
Groupdel news
Groupdel uuucp
Groupdel games
Groupdel dip
Similarly, the group accounts created by default for system installation are deleted. This reduces the chances of being attacked.
2.2 User password settings:
The minimum length of the default password for linux installation is 5 bytes, but this is not enough. set it to 8 bytes. To change the shortest password length, edit the login. defs File (vi/etc/login. defs)
PASS_MAX_DAYS 99999 # maximum password validity period (default)
PASS_MIN_DAYS 0 # set the minimum password validity period
PASS_MIN_LEN 5 # set the minimum password length
PASS_WARN_AGE 7 # How many days in advance to warn that the user password is about to expire.
2.3 modify the automatic account cancellation time:
The root account has the highest privilege in Linux. If the system administrator forgets to log out of the root account before leaving the system, this poses a major security risk and should be automatically logged out by the system. You can implement this function by modifying the "TMOUT" parameter in your account. TMOUT is calculated in seconds. Edit your profile File (vi/etc/profile) and add the following line after "HISTSIZE =:
TMOUT = 300
300 indicates 300 seconds, that is, 5 minutes. In this way, if the user logged on to the system does not take action within five minutes, the system will automatically cancel the account.
2.4 lock the system's user name and password for file storage:
Chattr + I/etc/passwd
Chattr + I/etc/shadow
Chattr + I/etc/gshadow
Chattr + I/etc/group
Note: chattr is a command to change the file attributes. parameter I indicates that the file or directory cannot be changed at will, and here I indicates immutable ). View method: lsattr/etc/passwd
3. Service Management
In terms of service management in Linux systems, if you want to ensure the best security of services, the main thing is to upgrade the software version of the service itself, and the other is to disable services not used by the system, minimize services.
3.1 disable services not used by the system:
Cd/etc/init. d # enter the system init process Startup directory
There are two ways to disable the service under the init Directory. 1. convert the file name under the init directory *. the file name of the old class, that is, the file name, is modified. The service startup file cannot be found when the system starts. 2. use the chkconfig system command to disable the system startup level service.
Note: When you use any of the following methods, first check whether the service to be closed is a special service that must be enabled on the server to prevent the service from being properly used.
Method 1: modify the file name
Cd/etc/init. d/
Mv apmd. old # notebook needs
Mv netfs. old # nfs Client
Mv yppasswdd. old # NIS server, which has many vulnerabilities
Mv ypserv. old # NIS server, which has many vulnerabilities
Mv dhcpd. old # dhcp service
Mv portmap. old # required to run the rpc (Port 111) service
Mv lpd. old # Print Service
Mv nfs. old # NFS server with many vulnerabilities
Mv sendmail. old # email service with many vulnerabilities
Mv snmpd. old # SNMP, which allows remote users to obtain many system information
Mv rstatd. old # avoid running the r service. remote users can obtain a lot of information from it.
Mv atd. old # The scheduled running program service is similar to cron.
Second: use the chkcofig command to disable unused system services.
Chkconfig? Clevel 35 apmd off
Chkconfig? Clevel 35 netfs off
Chkconfig? Clevel 35 yppasswdd off
Chkconfig? Clevel 35 ypserv off
Chkconfig? Clevel 35 dhcpd off
Chkconfig? Clevel 35 portmap off
Chkconfig? Clevel 35 lpd off
Chkconfig? Clevel 35 nfs off
Chkconfig? Clevel 35 sendmail off
Chkconfig? Clevel 35 snmpd off
Chkconfig? Clevel 35 rstatd off
Chkconfig? Clevel 35 atd off
Note: 3 and 5 in the preceding chkcofig commands are the system startup types. 3 indicates the multi-purpose startup mode of the system, and 5 indicates the X startup mode of the system.

3.2 lock the system service port list file.
Main role: prevent unauthorized deletion or addition of services
Chattr + I/etc/services

3.3 Modify the root logon permission of the ssh service
Modify the ssh service configuration file so that the ssh service does not allow the root user to log on directly, so that the system is vulnerable to malicious logon attacks.
Vi/etct/ssh/sshd_config
PermitRootLogin yes
After removing the # before this line, modify it to PermitRootLogin no.
4. system file permissions
Linux file system security is mainly achieved by setting file permissions. Each Linux file or directory has three sets of attributes, which define the owner of the file or directory respectively, user Group and other user permissions (read-only, writable, executable, SUID allowed, and SGID allowed ). Note that the executable files with the SUID and SGID permissions will be granted to the process owner during the running of the program. if they are discovered and exploited by hackers, the system may be compromised.
4.1 modify the execution permission of the init directory file:
Chmod-R 700/etc/init. d /*
4.2 modify the SUID and SGID permissions of some system files:
Chmod a-s/usr/bin/chage
Chmod a-s/usr/bin/gpasswd
Chmod a-s/usr/bin/wall
Chmod a-s/usr/bin/chfn
Chmod a-s/usr/bin/chsh
Chmod a-s/usr/bin/newgrp
Chmod a-s/usr/bin/write
Chmod a-s/usr/sbin/usernetctl
Chmod a-s/usr/sbin/traceroute
Chmod a-s/bin/mount
Chmod a-s/bin/umount
Chmod a-s/bin/ping
Chmod a-s/sbin/netreport
4.3 modify the system boot file
Chmod 600/etc/grub. conf
Chattr + I/etc/grub. conf
5. system optimization
5.1 virtual memory optimization:
In general, linux's physical memory is almost completely used. This is very different from windows. its memory management mechanism makes full use of the system memory. it is not the same for windows to use some virtual memory no matter how large the memory is.
The three numbers in/proc/sys/vm/freepages are the current system: minimum memory blank page, minimum memory blank page, and maximum memory blank page.
Note that the system uses the virtual memory principle: if the number of blank pages is lower than the maximum number of blank pages, the disk swap space is used. Memory swap is used when the minimum blank page setting is reached. Memory is generally allocated in 4 k bytes per page. The minimum memory blank page setting is 2 times the number of memory in the system, the minimum memory blank page setting is 4 times the number of memory, and the maximum memory blank page setting is 6 times the system memory.
The following uses 1 GB memory as an example to modify the default virtual memory parameter size:
Echo "2048 4096 6444">/proc/sys/vm/freepages
6. log management
6.1 system boot log:
Dmesg
You can use the dmesg command to quickly view the boot log of the last system boot. Usually its
There is a lot of content, so you often want to transmit it to a reader through a pipeline.
6.2 system running logs:
A. Linux logs are stored in the/var/log directory. There are several log files maintained by the system, but other services and programs may also put their logs here. Most logs can only be read by the root user. However, you only need to modify the file access permission to allow others to read the logs.
The following are common systems:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.