How to Protect Linux machines on the Internet through system management
Source: Internet
Author: User
Article Title: how to protect Linux machines on the Internet through system management. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Preface
Many enterprises and organizations on the Internet use Linux as the server platform. When these servers are connected to the Internet to provide application services, they will inevitably become the targets of attacks. This article discusses some basic knowledge about Linux system security configuration to help you protect the Linux system. Although Red Hat 6.0 is used as an example here, it should also be applicable to other Linux releases.
Install
The first step in configuring system security is preferably at the beginning of the system-operating system security. Because the firewall is configured, you absolutely cannot trust any previous system installation and configuration. Instead, you must start with a new installation to truly ensure the integrity of system security.
Put your system in a separate (or isolated) network. Never allow unprotected systems to connect to other networks or the Internet for possible attacks. In my personal experience, a new installation system connected to the Internet can be scanned and infiltrated within 15 minutes to gain full control. You may need another machine to obtain important tools and security patches from the Internet, and then transfer them to a separate "configuration Network.
When you place the machines to be used as firewalls in an isolated network, you can start the next step. The first step is to select the software package to be installed on the operating system. For Red Hat 6.0, three installation options are available: Workstation, Server, and M ). I personally strongly recommend "custom", because this allows you to choose which services to add and how to partition the hard disk. The installation policy is to "minimize" installation when maximum efficiency is maintained. The less software the system has, the less potential security vulnerabilities it has. For example, if you do not need News or Real Audio Server, do not install it. One advantage of Linux is that if you change your mind later, you can easily add required software packages. No matter which installation method is selected, the manual page and HOWTO document should be indispensable. Although it may increase the system risk, they are sometimes particularly useful.
If you select "custom" installation, you will be prompted to perform hard disk partitioning. I personally prefer to make the root partition as big as possible and put everything there. Then, we do need to create several partitions to protect the root partition. Because if the root partition is full of data such as system logs or emails, a denial of service may occur, or even cause a system crash.
Therefore, I always recommend setting a separate partition for/var. /Var is used to store all the logs and emails of the system. separating/var partitions can effectively protect the root partition from being filled with the data. For many network environments, it is sufficient to set the/var partition to be at least MB. In addition, you can consider creating or retaining separate partitions for certain specific services or applications, especially sensitive log records. If users in the system cannot be fully trusted, they may need to create separate partitions for/home to avoid malicious attacks to/root partitions. For an independent server, the following is a partition instance:
/-Everything else/var-400 MB swap-(I normally go with 256 MB)
After the system is installed and restarted, install necessary security patches. For Red Hat, you can go to http://www.redhat.com/#/support/updates.htmlto find all the security patch programs. Security patches are essential for maintaining a secure firewall and should be updated frequently. Bugtraq@securityfocus.com or redhat-watch-list-request@redhat.com is the best resource for getting the latest security vulnerability information. If you do not install these patches, your system may be vulnerable to intrusion. Remember to get these patches from another machine mentioned above, the firewall machine should still be in the isolated network. For the Red Hat system, downloading the RPM package will make the system update easier. For example, an instance that performs a security upgrade on wu-ftpd:
Rpm-Uvh wu-ftpd-2.6.0-14.6x.i386.rpm
If the system is already on the Internet, you can install it directly on the Internet:
We recommend that you use autorpm to update the RPM software package. This command line tool analyzes and determines which. The rpm package needs to be upgraded and will automatically download and install the upgrade file from the Red Hat website (if you want. This tool is flexible and simple to run in cron, so that your system will automatically check for updates on a regular basis, you can also send an email to the administrator reminding the system of the upgrade.
Close service
Once the installation package and patch of the system are installed and restarted, we can now configure security enhancement for the operating system. The security enhancement configuration mainly includes closing the service, adding logs, adjusting several files, and configuring TCP Wrappers. The first step is to close the service.
By default, Solaris is a high-performance operating system that provides many useful services. However, most of the services in the firewall are not required and may be a security risk. First, modify the/etc/inetd. conf file. This file defines the services that the/usr/sbin/inetd Super daemon needs to listen. By default,/etc/inetd. conf starts 35 services. However, up to two services are required: ftp and telnet. other services are not required. you can comment them out (close ). This is important because many services monitored by inetd have serious security threats, such as popd, imapd, and rsh. the following command lists the services that the inetd daemon will listen to. Make sure to comment out the line of the unnecessary services (add "#" at the beginning of the line ):
Grep-v "^ #"/etc/inetd. conf
Next, modify the files in the/etc/rc2.d directory and/etc/rc3.d directory. Here you can find the startup script executed by the init process. Many of them are not needed. To cancel executing a script during startup, you only need to change the starting uppercase S of the corresponding file name to lowercase s. In addition, the Red Hat system has a good tool to disable the service. Enter "/usr/sbin/setup" in the command line, select "System Services", and then select the script to be executed at System startup. Another method is to include the chkconfig tool in most releases. The following startup script is installed by default, but is usually not required. If you are sure you do not need them, you should disable them from starting. Note that the numbers are used to determine the execution sequence and may change in different release versions. The script starting with an uppercase key is used to kill services that are already running.
S05apmd (only needed for laptops) S10xntpd (Network Time Protocol) S11portmap (required if RPC service is running) S15sound (save sound card settings) S15netfs (NFS client, used to install the file system from the NFS server) S20rstatd (excessive information exposed to remote users) S20rusersd S20rwhod S20rwalld S20bootparamd (used for diskless clients, usually not required) S25squid (proxy server) s34yppasswdd (this service is required if the system runs the NIS server) S35ypserv (this service is required if the system runs the NIS server) S35dhcpd (start the DHCP server daemon process) S40atd (at service, similar to cron services, but the system usually does not need) S45pcmcia (only for laptops) S50snmpd (SNMP daemon, too much information exposed to remote users) S55named (DNS service . To run DNS, upgrade to the latest version) S55routed (RIP, which should be started only when required) S60lpd (print service) S60mars-nwe (Netware file and print server) s60nfs (used for NFS servers. Unless required, this service should not run) S72amd (AutoMount daemon, used to automatically install remote file system) S75gated (used to run other routing protocols, such as OSPF) s80sendmail (close if you do not need to receive or forward emails. At this time, you can still send an email) S85httpd (Apache server, we recommend you upgrade to the latest version) S87ypbind (only required by the NIS client) S90xfs (X Windows font server S95innd (News server) s99linuxconf (remote Linux system configuration through a browser)
To know how many services are running before modifying the startup script, enter:
Ps aux | wc-l
Modify the startup script, restart the system, and enter the preceding command again to calculate the number of services reduced. The fewer services are running, the better the security. Run the following command to know how many services are running:
Netstat-na -- ip
Logs and system adjustments
After canceling the service as much as possible, the next step is to configure the system log. All system logs are stored in the/var/log directory. Lack of time-saving, Linux has good log settings, except ftp. there are two methods to record ftp logs, configure the/etc/ftpaccess file or edit/etc/inetd. conf. it is recommended to use relatively simple edit/etc/inetd. conf file. You can edit the/etc/inetd. conf file as follows to record all logs of all FTP sessions.
Ftp stream tcp nowait root/usr/sbin/tcpd in. ftpd-l-L-I-o
-- The following is selected from the ftp manual page --
If the-l parameter is specified, syslog records every ftp session. If the-L parameter is specified, the command log is activated once the ftp server is called. This causes the server to record all USER commands. Note: If a user enters the password accidentally during user name input, the password will be recorded by syslog! If the-I parameter is specified, all files received by the ftpd server will be recorded in xferlog. If the-o parameter is specified, all files sent by the ftpd server will be recorded in xferlog.
-- Snip --
The next step is system adjustment. This includes the management of multiple files. The first thing is to ensure the security of the/etc/passwd file. First, make sure that the system uses the/etc/shadow file. this file stores all user passwords in ciphertext format and only allows the root user to access it. This prevents the user password from being easily accessed and cracked. Red Hat 6.0 lacks the shadow password system, but it is necessary to check and determine. Run the following command to automatically convert the password system to the/etc/shadow password system:
Pwconv
Step 2: delete many default system accounts in the/etc/passwd file. Linux provides these accounts for many system operations that are rarely needed. If you do not need these accounts, delete them. The more accounts, the more likely the system will be infiltrated. For example, if the "news" account does not run the nntp newsgroup server, you do not need this account (be sure to update the/etc/cron. hourly file because the script involves the "news" user ). In addition, you must delete the "ftp" account because this account is only used for anonymous FTP access.
We also need to modify the/etc/ftpusers file. Any account that has been included in the file will not be able to ftp to the system. It is usually used to restrict System accounts, such as root and bin, and prohibit FTP sessions of these accounts. The file has been created in Linux. Ensure that the root user is included in the file to prohibit the ftp session between the root user and the system. Check and confirm that all accounts requiring FTP to the firewall ** no ** are in the/etc/ftpusers file.
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