CentOS系统安装后的初始环境设置

系统 Linux
在CentOS系统安装好之后,对安全性以及对硬件的适应性方面不合适的情况下,对新的CentOS系统进行初始环境设置。

在CentOS系统安装好之后,安全性以及对硬件的适应性方面,可能并不完全符合我们的实际情况。在这里,对新的CentOS系统进行初始环境设置将以如下方面为原则:
1,为了安全,尽***可能将访问限制限制到可能的***程度;
2,为了节省内存及 CPU 使用率(以及安全方面的考虑),尽***可能将不需要的服务关闭;
3,为了减少误操作可能带来的损失,平时通过 wheel 组用户登录进行系统管理;
4,为了让系统变的更加轻便、快速,将内核中不需要的模块卸载;

CentOS系统 4.4 的安装后初始环境设定
 
安装完毕重新启动系统后,出现如下的状态:
CentOS release 4.4 (Final)
Kernel 2.6.9-42.EL on an i686
sample login:   ← 根据安装时网络设置的情况的不同,本站以“sample”,其位置显示的是你设置好的主机名。

[1] 系统的登录与退出

sample login: root ← 用root用户来登录系统,输入用户名root
Password: ← 在这里输入安装时设置的root密码,输入时密码不会被显示
[root@sample ~]# ← root用户登录成功,提示符为“#”。若一般用户登录成功后,提示符为“$”
[root@sample ~]# exit ← 退出系统
sample login: ← 退出系统成功

[2] 一般用户的建立与删除

[root@sample ~]# useradd centospub ← 建立用户名为 centospub 的一般用户
[root@sample ~]# passwd centospub ← 为用户 centospub 设置密码
Changing password for user centospub.
New UNIX password:  ← 输入密码(密码不会被显示)
Retype new UNIX password:  ← 再次输入密码确认两次密码一致
passwd: all authentication tokens updated successfully. ← 密码设置成功
[root@sample ~]# userdel -r centospub ← 删除用户名为 centospub 的一般用户

[3] 通过一般用户登录为root用户

因为root用户对系统具有全权的操作权限,为了避免一些失误的操作,建议在一般情况下,以一般用户登录系统,必要的时候需要root操作权限时,再通过“su -”命令来登录为root用户进行操作。
[centospub@sample ~]$  ← 提示符为“$”,说明当前状态为一般用户CentOS系统pub登录在系统中
[centospub@sample ~]$ su -  ← 输入登录为root用户的命令
Password:   ← 输入root密码(密码不会被显示),回车
[root@sample ~]# ← 成功登录为root用户,提示符变为“#”
[root@sample ~]# exit ← 回到一般用户的登录状态
[centospub@sample ~]$ ← 提示符变为“$”,回到了一般用户CentOS系统pub登录系统的状态

[4] 建立管理员组内一般用户

在 一般情况下,一般用户通过执行“su -”命令、输入正确的root密码,可以登录为root用户来对系统进行管理员级别的配置。但是,为了更进一步加强系统的安全性,有必要建立一个管理员的 组,只允许这个组的用户来执行“su -”命令登录为root用户,而让其他组的用户即使执行“su -”、输入了正确的root密码,也无法登录为root用户。在UNIX下,这个组的名称通常为“wheel”。

[root@sample ~]# usermod -G wheel centospub  ← 将一般用户 centospub 加在管理员组wheel组中
[root@sample ~]# vi /etc/pam.d/su  ← 打开这个配置文件
#auth required /lib/security/$ISA/pam_wheel.so use_uid   ← 找到此行,去掉行首的“#”
auth required /lib/security/$ISA/pam_wheel.so use_uid  ← 变为此状态(大约在第6行的位置)
[root@sample ~]# echo "SU_WHEEL_ONLY yes" >> /etc/login.defs ← 添加语句到行末

以上操作完成后,可以再建立一个新用户,然后用这个新建的用户测试会发现,没有加入到wheel组的用户,执行“su -”命令,即使输入了正确的root密码,也无法登录为root用户。

[5] 建立PPPoE连接(非xDSL接入方式的用户可跳过此步骤)

  1. [root@sample ~]# adsl-setup  ← 建立ADSL连接  
  2. Welcome to the ADSL client setup. First, I will run some checks on  
  3. your system to make sure the PPPoE client is installed properly...  
  4. LOGIN NAME  
  5. Enter your Login Name (default root): ← 填入ADSL连接的用户名  
  6. INTERFACE  
  7. Enter the Ethernet interface connected to the ADSL modem  
  8. For Solaris, this is likely to be something like /dev/hme0.  
  9. For Linux, it will be ethX, where 'X' is a number.  
  10. (default eth0):  ← 指定网络接入设备,一块网卡的情况下,一般为默认eth0  
  11. Do you want the link to come up on demand, or stay up continuously?  
  12. If you want it to come up on demand, enter the idle time in seconds  
  13. after which the link should be dropped. If you want the link to  
  14. stay up permanently, enter 'no' (two letters, lower-case.)  
  15. NOTE: Demand-activated links do not interact well with dynamic IP  
  16. addresses. You may have some problems with demand-activated links.  
  17. Enter the demand value (default no):  ← 直接按回车,接受默认设置  
  18. DNS  
  19. Please enter the IP address of your ISP's primary DNS server.  
  20. If your ISP claims that 'the server will provide dynamic DNS addresses',  
  21. enter 'server' (all lower-case) here.  
  22. If you just press enter, I will assume you know what you are  
  23. doing and not modify your DNS setup.  
  24. Enter the DNS information here:  ← 如果知道DNS服务器的信息在此填入。不知道的情况按回车跳过  
  25. PASSWORD  
  26. Please enter your Password: ← 输入ADSL的连接密码  
  27. Please re-enter your Password: ← 再次确认输入ADSL的连接密码  
  28. USERCTRL  
  29. Please enter 'yes' (two letters, lower-case.) if you want to allow  
  30. normal user to start or stop DSL connection (default yes): no ← 填入no,不允许一般用户控制PPPoE的连接  
  31. FIREWALLING  
  32. Please choose the firewall rules to use. Note that these rules are  
  33. very basic. You are strongly encouraged to use a more sophisticated  
  34. firewall setup; however, these will provide basic security. If you  
  35. are running any servers on your machine, you must choose 'NONE' and  
  36. set up firewalling yourself. Otherwise, the firewall rules will deny  
  37. access to all standard servers like Web, e-mail, ftp, etc. If you  
  38. are using SSH, the rules will block outgoing SSH connections which  
  39. allocate a privileged source port.  
  40.  
  41. The firewall choices are:  
  42. 0 - NONE: This script will not set any firewall rules. You are responsible  
  43. for ensuring the security of your machine. You are STRONGLY  
  44. recommended to use some kind of firewall rules.  
  45. 1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation  
  46. 2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway  
  47. for a LAN  
  48. Choose a type of firewall (0-2): 0 ← 输入0,不在这里使用防火墙  
  49.  
  50. Start this connection at boot time  
  51. Do you want to start this connection at boot time?  
  52. Please enter no or yes (default no): yes ← 填入yes,在系统启动时自动连接ADSL  
  53. ** Summary of what you entered **  
  54. Ethernet Interface: eth0  
  55. User name: caun870293@ca.dti.ne.jp  
  56. Activate-on-demand: No  
  57. DNS: Do not adjust  
  58. Firewalling: NONE  
  59. User Control: no  
  60. Accept these settings and adjust configuration files (y/n)? y ← 配置信息确认无误后,键入y同意设置  
  61. Adjusting /etc/sysconfig/network-scripts/ifcfg-ppp0  
  62. Adjusting /etc/ppp/chap-secrets and /etc/ppp/pap-secrets  
  63. (But first backing it up to /etc/ppp/chap-secrets.bak)  
  64. (But first backing it up to /etc/ppp/pap-secrets.bak)  
  65. ?  
  66. Congratulations, it should be all set up!  
  67. Type '/sbin/ifup ppp0' to bring up your xDSL link and '/sbin/ifdown ppp0'  
  68. to bring it down.  
  69. Type '/sbin/adsl-status /etc/sysconfig/network-scripts/ifcfg-ppp0'  
  70. to see the link status.  
  71.  

然后,启动ADSL连接。
[root@sample ~]# adsl-start  ← 启动ADSL连接
[root@sample ~]#   ← 稍等片刻后若启动成功后出现提示符(无任何提示即意味着连接成功)
这时,通过“ifconfig”命令可以看到各网络接口的信息(IP地址等等)。

[6] root邮件的转送

在系统出现错误或有重要通知发送邮件给root的时候,让系统自动转送到我们通常使用的邮箱中,这样方便查阅相关报告和日志。
[root@sample ~]# vi /etc/aliases   ← 编辑aliases,添加如下行到文尾
root: yourname@yourserver.com ← 加入自己的邮箱地址
[root@sample ~]# newaliases ← 重建aliasesdb
/etc/aliases: 79 aliases, longest 19 bytes, 825 bytes total
[root@sample ~]# echo test | mail root ← 发送测试邮件给root

如果成功的话,会在刚刚填入的 yourname@yourserver.com 的邮箱中收到测试的邮件。

[7] locate命令用数据库更新及自动更新设定

locate命令是Linux下告诉搜索文件用的工具,它的原理和Windows下的“Google桌面搜索”有点类似,是通过事先建立数据库的方式,来达到高速查找目标文件的目的。

[root@sample ~]# vi /etc/updatedb.conf  ← 编辑locate数据库更新配置文件
DAILY_UPDATE=no  ← 找到这一行,将“no”改为“yes”
DAILY_UPDATE=yes  ← 变为此状态后,保存、退出
[root@sample ~]# updatedb  ← 运行locate数据库更新命令,稍等片刻…更新成功后出现提示符

[8] 定义yum的非官方库

在服务器构建的过程中,我们将要用到的一些工具不存在于CentOS系统中yum的官方库中,所以需要定义yum的非官方库文件,让一些必需的工具通过yum也能够安装。

  1. [root@sample ~]# vi /etc/yum.repos.d/dag.repo  ← 建立dag.repo,定义非官方库  
  2. [dag]  
  3. name=Dag RPM Repository for Red Hat Enterprise Linux  
  4. baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag  
  5. gpgcheck=1 
  6. enabled=1 
  7. [root@sample ~]# rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt  ← 导入非官方库的GPG  

[9] 停止打印服务

如果不准备提供打印服务,停止默认被设置为自动启动的打印服务。

 

  1. [root@sample ~]# /etc/rc.d/init.d/cups stop  ← 停止打印服务  
  2. Stopping cups:            [ OK ]    ← 停止服务成功,出现“OK”  
  3. [root@sample ~]# chkconfig cups off  ← 禁止打印服务自动启动  
  4. [root@sample ~]# chkconfig --list cups  ← 确认打印服务自启动设置状态  
  5. cups 0:off 1:off 2:off 3:off 4:off 5:off 6:off  ← 0-6都为off的状态就OK(当前打印服务自启动被禁止中)   
  6.  

[10] 停止ipv6

在CentOS系统默认的状态下,ipv6是被启用的状态。因为我们不使用ipv6,所以,停止ipv6,以***限度保证安全和快速。
首先再次确认一下ipv6功能是不是被启动的状态。

[root@sample ~]# ifconfig -a ← 列出全部网络接口信息

  1. eth0 Link encap:Ethernet HWaddr 00:0C:29:B6:16:A3  
  2. inet addr:192.168.0.13 Bcast:192.168.0.255 Mask:255.255.255.0  
  3. inet6 addr: fe80::20c:29ff:feb6:16a3/64 Scope:Link  
  4. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1  
  5. RX packets:84 errors:0 dropped:0 overruns:0 frame:0  
  6. TX packets:93 errors:0 dropped:0 overruns:0 carrier:0  
  7. collisions:0 txqueuelen:1000  
  8. RX bytes:10288 (10.0 KiB) TX bytes:9337 (9.1 KiB)  
  9. Interrupt:185 Base address:0x1400   
  10. lo Link encap:Local Loopback  
  11. inet addr:127.0.0.1 Mask:255.0.0.0  
  12. inet6 addr: ::1/128 Scope:Host  
  13. UP LOOPBACK RUNNING MTU:16436 Metric:1  
  14. RX packets:12 errors:0 dropped:0 overruns:0 frame:0  
  15. TX packets:12 errors:0 dropped:0 overruns:0 carrier:0  
  16. collisions:0 txqueuelen:0  
  17. RX bytes:952 (952.0 b) TX bytes:952 (952.0 b)  
  18. sit0 Link encap:IPv6-in-IPv4 ← 确认ipv6是被启动的状态  
  19. NOARP MTU:1480 Metric:1  
  20. RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
  21. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0  
  22. collisions:0 txqueuelen:0  
  23. RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)   
  24.  

CentOS系统安装后然后修改相应配置文件,停止ipv6。

[root@sample ~]# vi /etc/modprobe.conf ← 修改相应配置文件,添加如下行到文尾:
alias net-pf-10 off
alias ipv6 off
[root@sample ~]# shutdown -r now  ← 重新启动系统,使设置生效

***确认ipv6的功能已经被关闭。

  1. [root@sample ~]# ifconfig -a ← 列出全部网络接口信息  
  2. eth0 Link encap:Ethernet HWaddr 00:0C:29:B6:16:A3  
  3. inet addr:192.168.0.13 Bcast:192.168.0.255 Mask:255.255.255.0  
  4. inet6 addr: fe80::20c:29ff:feb6:16a3/64 Scope:Link  
  5. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1  
  6. RX packets:84 errors:0 dropped:0 overruns:0 frame:0  
  7. TX packets:93 errors:0 dropped:0 overruns:0 carrier:0  
  8. collisions:0 txqueuelen:1000  
  9. RX bytes:10288 (10.0 KiB) TX bytes:9337 (9.1 KiB)  
  10. Interrupt:185 Base address:0x1400 lo Link encap:Local Loopback  
  11. inet addr:127.0.0.1 Mask:255.0.0.0  
  12. inet6 addr: ::1/128 Scope:Host  
  13. UP LOOPBACK RUNNING MTU:16436 Metric:1  
  14. RX packets:12 errors:0 dropped:0 overruns:0 frame:0  
  15. TX packets:12 errors:0 dropped:0 overruns:0 carrier:0  
  16. collisions:0 txqueuelen:0  
  17. RX bytes:952 (952.0 b) TX bytes:952 (952.0 b)  

(确认ipv6的相关信息没有被列出,说明ipv6功能已被关闭。)

【编辑推荐】

  1. CentOS系统是Linux常见版本之一
  2. CentOS系统CPU过热处理的解决方法
  3. CentOS系统操作下安装相关各种软件
  4. MySQL CentOS系统管理文件安装
  5. Linux centos系统的IP设置配置
责任编辑:小霞
相关推荐

2010-03-25 14:42:33

2011-03-09 16:16:56

CentOSLAMP

2010-02-23 14:45:52

CentOS LEMP

2010-02-22 18:18:14

CentOS vsft

2010-02-22 16:18:29

CentOS cact

2010-03-26 12:50:02

CentOS系统

2011-08-19 16:59:54

windows7初始设置项

2010-03-11 19:25:35

Python环境

2010-01-13 17:24:07

Centos 5.1系

2010-01-15 13:55:17

CentOS mail

2011-02-23 14:38:39

安装CentOS vsftpd

2010-01-13 10:14:45

2011-02-23 14:38:39

安装CentOS vsftpd

2011-03-25 16:23:43

CentOSNagios

2011-08-19 17:00:47

windows7初始设置项

2010-03-30 15:24:28

CentOS系统

2011-03-31 16:46:10

LinuxMySQL

2011-03-09 16:28:25

2010-03-01 16:51:53

CentOS VMwa

2010-01-13 14:32:07

Linux cento
点赞
收藏

51CTO技术栈公众号