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

   < 系统安装后的初始环境设置 > (最近更新日:2006/12/24)
前  言

  在 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 ~]$  ← 提示符为“$”,说明当前状态为通常用户centospub登陆在系统中

[centospub@sample ~]$ su -  ← 输入登陆为root用户的命令
Password:   ← 输入root密码(密码不会被显示),回车

[root@sample ~]# ← 成功登陆为root用户,提示符变为“#”

[root@sample ~]# exit ← 回到通常用户的登陆状态

[centospub@sample ~]$ ← 提示符变为“$”,回到了通常用户centospub登陆系统的状态

[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接入方式的用户可跳过此步骤)

[root@sample ~]# adsl-setup  ← 创建ADSL链接

Welcome to the ADSL client setup. First, I will run some checks on
your system to make sure the PPPoE client is installed properly... web

LOGIN NAME 数据库

Enter your Login Name (default root): ← 填入ADSL链接的用户名 centos

INTERFACE 安全

Enter the Ethernet interface connected to the ADSL modem
For Solaris, this is likely to be something like /dev/hme0.
For Linux, it will be ethX, where 'X' is a number.
(default eth0):
  ← 指定网络接入设备,一块网卡的状况下,通常为默认eth0 服务器

Do you want the link to come up on demand, or stay up continuously?
If you want it to come up on demand, enter the idle time in seconds
after which the link should be dropped. If you want the link to
stay up permanently, enter 'no' (two letters, lower-case.)
NOTE: Demand-activated links do not interact well with dynamic IP
addresses. You may have some problems with demand-activated links.
Enter the demand value (default no):
  ← 直接按回车,接受默认设置 网络

DNS ide

Please enter the IP address of your ISP's primary DNS server.
If your ISP claims that 'the server will provide dynamic DNS addresses',
enter 'server' (all lower-case) here.
If you just press enter, I will assume you know what you are
doing and not modify your DNS setup.
Enter the DNS information here:
  ← 若是知道DNS服务器的信息在此填入。不知道的状况按回车跳过 工具

PASSWORD oop

Please enter your Password: ← 输入ADSL的链接密码
Please re-enter your Password: ← 再次确认输入ADSL的链接密码 测试

USERCTRL

Please enter 'yes' (two letters, lower-case.) if you want to allow
normal user to start or stop DSL connection (default yes):
no ← 填入no,不容许通常用户控制PPPoE的链接

FIREWALLING

Please choose the firewall rules to use. Note that these rules are
very basic. You are strongly encouraged to use a more sophisticated
firewall setup; however, these will provide basic security. If you
are running any servers on your machine, you must choose 'NONE' and
set up firewalling yourself. Otherwise, the firewall rules will deny
access to all standard servers like Web, e-mail, ftp, etc. If you
are using SSH, the rules will block outgoing SSH connections which
allocate a privileged source port.

The firewall choices are:
0 - NONE: This script will not set any firewall rules. You are responsible
for ensuring the security of your machine. You are STRONGLY
recommended to use some kind of firewall rules.
1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation
2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway
for a LAN
Choose a type of firewall (0-2):
0 ← 输入0,不在这里使用防火墙

Start this connection at boot time

Do you want to start this connection at boot time?
Please enter no or yes (default no):
yes ← 填入yes,在系统启动时自动链接ADSL

** Summary of what you entered **

Ethernet Interface: eth0
User name: caun870293@ca.dti.ne.jp
Activate-on-demand: No
DNS: Do not adjust
Firewalling: NONE
User Control: no
Accept these settings and adjust configuration files (y/n)?
y ← 配置信息确认无误后,键入y赞成设置
Adjusting /etc/sysconfig/network-scripts/ifcfg-ppp0
Adjusting /etc/ppp/chap-secrets and /etc/ppp/pap-secrets
(But first backing it up to /etc/ppp/chap-secrets.bak)
(But first backing it up to /etc/ppp/pap-secrets.bak)

?

Congratulations, it should be all set up!

Type '/sbin/ifup ppp0' to bring up your xDSL link and '/sbin/ifdown ppp0'
to bring it down.
Type '/sbin/adsl-status /etc/sysconfig/network-scripts/ifcfg-ppp0'
to see the link status.


  而后,启动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也可以安装。

[root@sample ~]# vi /etc/yum.repos.d/dag.repo  ← 创建dag.repo,定义非官方库

[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1

[root@sample ~]# rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt  ← 导入非官方库的GPG

[9] 中止打印服务

  若是不许备提供打印服务,中止默认被设置为自动启动的打印服务。

[root@sample ~]# /etc/rc.d/init.d/cups stop  ← 中止打印服务
Stopping cups:            [ OK ]    ← 中止服务成功,出现“OK”

[root@sample ~]# chkconfig cups off  ← 禁止打印服务自动启动

[root@sample ~]# chkconfig --list cups  ← 确认打印服务自启动设置状态
cups 0:off 1:off 2:off 3:off 4:off 5:off 6:off  ← 0-6都为off的状态就OK(当前打印服务自启动被禁止中)

[10] 中止ipv6

  在CentOS默认的状态下,ipv6是被启用的状态。由于咱们不使用ipv6,因此,中止ipv6,以最大限度保证安全和快速。

  首先再次确认一下ipv6功能是否是被启动的状态。

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

eth0 Link encap:Ethernet HWaddr 00:0C:29:B6:16:A3
inet addr:192.168.0.13 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feb6:16a3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:84 errors:0 dropped:0 overruns:0 frame:0
TX packets:93 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10288 (10.0 KiB) TX bytes:9337 (9.1 KiB)
Interrupt:185 Base address:0x1400

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:952 (952.0 b) TX bytes:952 (952.0 b)

sit0 Link encap:IPv6-in-IPv4 ← 确认ipv6是被启动的状态
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

  而后修改相应配置文件,中止ipv6。

[root@sample ~]# vi /etc/modprobe.conf ← 修改相应配置文件,添加以下行到文尾:

alias net-pf-10 off
alias ipv6 off

[root@sample ~]# shutdown -r now  ← 从新启动系统,使设置生效

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

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

eth0 Link encap:Ethernet HWaddr 00:0C:29:B6:16:A3
inet addr:192.168.0.13 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feb6:16a3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:84 errors:0 dropped:0 overruns:0 frame:0
TX packets:93 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10288 (10.0 KiB) TX bytes:9337 (9.1 KiB)
Interrupt:185 Base address:0x1400
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:952 (952.0 b) TX bytes:952 (952.0 b)

(确认ipv6的相关信息没有被列出,说明ipv6功能已被关闭。)
相关文章
相关标签/搜索