Centos 系统安全方面.docx
- 文档编号:9703534
- 上传时间:2023-05-20
- 格式:DOCX
- 页数:13
- 大小:23.79KB
Centos 系统安全方面.docx
《Centos 系统安全方面.docx》由会员分享,可在线阅读,更多相关《Centos 系统安全方面.docx(13页珍藏版)》请在冰点文库上搜索。
Centos系统安全方面
一.Centos系统安全方面
1、用防火墙关闭不须要的任何端口,别人PING不到服务器,威胁自然减少了一大半
2、更改SSH端口,最好改为10000以上,别人扫描到端口的机率也会下降
3、删除系统臃肿多余的账号:
userdeladm
userdellp
userdelsync
userdelshutdown
userdelhalt
userdelnews
userdeluucp
userdeloperator
userdelgames
userdelgopher
userdelftp如果你不允许匿名FTP,就删掉这个用户帐号
groupdeladm
groupdellp
groupdelnews
groupdeluucp
groupdelgames
groupdeldip
groupdelpppusers
4、更改下列文件权限,使任何人没有更改账户权限:
chattr+i/etc/passwd
chattr+i/etc/shadow
chattr+i/etc/group
chattr+i/etc/gshadow
5、chmod600/etc/xinetd.conf
6、关闭FTP匿名用户登陆
二.PHP安全篇
1、开启安全模式(做为商业应用的服务器不建议开启)
#vi/usr/local/Zend/etc/php.ini(没装ZO时php.ini文件位置为:
/etc/php.ini)
safe_mode=On
2、锁定PHP程序应用目录
#vi/etc/httpd/conf.d/virtualhost.conf
加入
php_admin_valueopen_basedir/home/***(***为站点目录)
3、千万不要给不必要的目录给写权限,也就是777权限,根目录保持为711权限,如果不能运行PHP请改为755
4、屏蔽PHP不安全的参数(webshell)
#vi/usr/local/Zend/etc/php.ini(没装ZO时php.ini文件位置为:
/etc/php.ini)
disable_functions=system,exec,shell_exec,passthru,popen
以下为我的服务器屏蔽参数:
disable_functions=passthru,exec,shell_exec,system,set_time_limit,ini_alter,dl,
pfsockopen,openlog,syslog,readlink,symlink,link,leak,fsockopen,popen,escapeshell
cmd,error_log
<系统安装后的初始环境设置>(最近更新日:
2006/12/24)
前 言
在CentOS安装好之后,安全性以及对硬件的适应性方面,可能并不完全符合我们的实际情况。
在这里,对新的CentOS系统进行初始环境设置将以如下方面为原则:
1,为了安全,尽最大可能将访问限制限制到可能的最大程度;
2,为了节省内存及CPU使用率(以及安全方面的考虑),尽最大可能将不需要的服务关闭;
3,为了减少误操作可能带来的损失,平时通过wheel组用户登录进行系统管理;
4,为了让系统变的更加轻便、快速,将内核中不需要的模块卸载;
…………
CentOS4.4的安装后初始环境设定
安装完毕重新启动系统后,出现如下的状态:
CentOSrelease4.4(Final)
Kernel2.6.9-42.ELonani686
samplelogin:
←根据安装时网络设置的情况的不同,本站以“sample”,其位置显示的是你设置好的主机名。
[1]系统的登录与退出
samplelogin:
root ←用root用户来登录系统,输入用户名root
Password:
←在这里输入安装时设置的root密码,输入时密码不会被显示
[root@sample~]# ←root用户登录成功,提示符为“#”。
若一般用户登录成功后,提示符为“$”
[root@sample~]#exit ←退出系统
samplelogin:
←退出系统成功
[2]一般用户的建立与删除
[root@sample~]#useraddcentospub ←建立用户名为centospub的一般用户
[root@sample~]#passwdcentospub ←为用户centospub设置密码
Changingpasswordforusercentospub.
NewUNIXpassword:
←输入密码(密码不会被显示)
RetypenewUNIXpassword:
←再次输入密码确认两次密码一致
passwd:
allauthenticationtokensupdatedsuccessfully. ←密码设置成功
[root@sample~]#userdel-rcentospub ←删除用户名为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-Gwheelcentospub ←将一般用户centospub加在管理员组wheel组中
[root@sample~]#vi/etc/pam.d/su ←打开这个配置文件
#authrequired/lib/security/$ISA/pam_wheel.souse_uid ←找到此行,去掉行首的“#”
↓
authrequired/lib/security/$ISA/pam_wheel.souse_uid ←变为此状态(大约在第6行的位置)
[root@sample~]#echo"SU_WHEEL_ONLYyes">>/etc/login.defs ←添加语句到行末
以上操作完成后,可以再建立一个新用户,然后用这个新建的用户测试会发现,没有加入到wheel组的用户,执行“su-”命令,即使输入了正确的root密码,也无法登录为root用户。
[5]建立PPPoE连接(非xDSL接入方式的用户可跳过此步骤)
[root@sample~]#adsl-setup ←建立ADSL连接
WelcometotheADSLclientsetup.First,Iwillrunsomecheckson
yoursystemtomakesurethePPPoEclientisinstalledproperly...
LOGINNAME
EnteryourLoginName(defaultroot):
←填入ADSL连接的用户名
INTERFACE
EntertheEthernetinterfaceconnectedtotheADSLmodem
ForSolaris,thisislikelytobesomethinglike/dev/hme0.
ForLinux,itwillbeethX,where'X'isanumber.
(defaulteth0):
←指定网络接入设备,一块网卡的情况下,一般为默认eth0
Doyouwantthelinktocomeupondemand,orstayupcontinuously?
Ifyouwantittocomeupondemand,entertheidletimeinseconds
afterwhichthelinkshouldbedropped.Ifyouwantthelinkto
stayuppermanently,enter'no'(twoletters,lower-case.)
NOTE:
Demand-activatedlinksdonotinteractwellwithdynamicIP
addresses.Youmayhavesomeproblemswithdemand-activatedlinks.
Enterthedemandvalue(defaultno):
←直接按回车,接受默认设置
DNS
PleaseentertheIPaddressofyourISP'sprimaryDNSserver.
IfyourISPclaimsthat'theserverwillprovidedynamicDNSaddresses',
enter'server'(alllower-case)here.
Ifyoujustpressenter,Iwillassumeyouknowwhatyouare
doingandnotmodifyyourDNSsetup.
EntertheDNSinformationhere:
←如果知道DNS服务器的信息在此填入。
不知道的情况按回车跳过
PASSWORD
PleaseenteryourPassword:
←输入ADSL的连接密码
Pleasere-enteryourPassword:
←再次确认输入ADSL的连接密码
USERCTRL
Pleaseenter'yes'(twoletters,lower-case.)ifyouwanttoallow
normalusertostartorstopDSLconnection(defaultyes):
no ←填入no,不允许一般用户控制PPPoE的连接
FIREWALLING
Pleasechoosethefirewallrulestouse.Notethattheserulesare
verybasic.Youarestronglyencouragedtouseamoresophisticated
firewallsetup;however,thesewillprovidebasicsecurity.Ifyou
arerunninganyserversonyourmachine,youmustchoose'NONE'and
setupfirewallingyourself.Otherwise,thefirewallruleswilldeny
accesstoallstandardserverslikeWeb,e-mail,ftp,etc.Ifyou
areusingSSH,theruleswillblockoutgoingSSHconnectionswhich
allocateaprivilegedsourceport.
Thefirewallchoicesare:
0-NONE:
Thisscriptwillnotsetanyfirewallrules.Youareresponsible
forensuringthesecurityofyourmachine.YouareSTRONGLY
recommendedtousesomekindoffirewallrules.
1-STANDALONE:
Appropriateforabasicstand-aloneweb-surfingworkstation
2-MASQUERADE:
AppropriateforamachineactingasanInternetgateway
foraLAN
Chooseatypeoffirewall(0-2):
0 ←输入0,不在这里使用防火墙
Startthisconnectionatboottime
Doyouwanttostartthisconnectionatboottime?
Pleaseenternooryes(defaultno):
yes ←填入yes,在系统启动时自动连接ADSL
**Summaryofwhatyouentered**
EthernetInterface:
eth0
Username:
caun870293@ca.dti.ne.jp
Activate-on-demand:
No
DNS:
Donotadjust
Firewalling:
NONE
UserControl:
no
Acceptthesesettingsandadjustconfigurationfiles(y/n)?
y ←配置信息确认无误后,键入y同意设置
Adjusting/etc/sysconfig/network-scripts/ifcfg-ppp0
Adjusting/etc/ppp/chap-secretsand/etc/ppp/pap-secrets
(Butfirstbackingitupto/etc/ppp/chap-secrets.bak)
(Butfirstbackingitupto/etc/ppp/pap-secrets.bak)
?
Congratulations,itshouldbeallsetup!
Type'/sbin/ifupppp0'tobringupyourxDSLlinkand'/sbin/ifdownppp0'
tobringitdown.
Type'/sbin/adsl-status/etc/sysconfig/network-scripts/ifcfg-ppp0'
toseethelinkstatus.
然后,启动ADSL连接。
[root@sample~]#adsl-start ←启动ADSL连接
[root@sample~]# ←稍等片刻后若启动成功后出现提示符(无任何提示即意味着连接成功)
这时,通过“ifconfig”命令可以看到各网络接口的信息(IP地址等等)。
[6]root邮件的转送
在系统出现错误或有重要通知发送邮件给root的时候,让系统自动转送到我们通常使用的邮箱中,这样方便查阅相关报告和日志。
[root@sample~]#vi/etc/aliases ←编辑aliases,添加如下行到文尾
root:
yourname@ ←加入自己的邮箱地址
[root@sample~]#newaliases ←重建aliasesdb
/etc/aliases:
79aliases,longest19bytes,825bytestotal
[root@sample~]#echotest|mailroot ←发送测试邮件给root
如果成功的话,会在刚刚填入的yourname@的邮箱中收到测试的邮件。
[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=DagRPMRepositoryforRedHatEnterpriseLinux
baseurl=http:
//apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1
[root@sample~]#rpm--import ←导入非官方库的GPG
[9]停止打印服务
如果不准备提供打印服务,停止默认被设置为自动启动的打印服务。
[root@sample~]#/etc/rc.d/init.d/cupsstop ←停止打印服务
Stoppingcups:
[OK] ←停止服务成功,出现“OK”
[root@sample~]#chkconfigcupsoff ←禁止打印服务自动启动
[root@sample~]#chkconfig--listcups ←确认打印服务自启动设置状态
cups0:
off1:
off2:
off3:
off4:
off5:
off6:
off ←0-6都为off的状态就OK(当前打印服务自启动被禁止中)
[10]停止ipv6
在CentOS默认的状态下,ipv6是被启用的状态。
因为我们不使用ipv6,所以,停止ipv6,以最大限度保证安全和快速。
首先再次确认一下ipv6功能是不是被启动的状态。
[root@sample~]#ifconfig-a ←列出全部网络接口信息
eth0Linkencap:
EthernetHWaddr00:
0C:
29:
B6:
16:
A3
inetaddr:
192.168.0.13Bcast:
192.168.0.255Mask:
255.255.255.0
inet6addr:
fe80:
:
20c:
29ff:
feb6:
16a3/64Scope:
Link
UPBROADCASTRUNNINGMULTICASTMTU:
1500Metric:
1
RXpackets:
84errors:
0dropped:
0overruns:
0frame:
0
TXpackets:
93errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0txqueuelen:
1000
RXbytes:
10288(10.0KiB)TXbytes:
9337(9.1KiB)
Interrupt:
185Baseaddress:
0x1400
loLinkencap:
LocalLoopback
inetaddr:
127.0.0.1Mask:
255.0.0.0
inet6addr:
:
:
1/128Scope:
Host
UPLOOPBACKRUNNINGMTU:
16436Metric:
1
RXpackets:
12errors:
0dropped:
0overruns:
0frame:
0
TXpackets:
12errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0txqueuelen:
0
RXbytes:
952(952.0b)TXbytes:
952(952.0b)
sit0Linkencap:
IPv6-in-IPv4 ←确认ipv6是被启动的状态
NOARPMTU:
1480Metric:
1
RXpackets:
0errors:
0dropped:
0overruns:
0frame:
0
TXpackets:
0errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0txqueuelen:
0
RXbytes:
0(0.0b)TXbytes:
0(0.0b)
然后修改相应配置文件,停止ipv6。
[root@sample~]#vi/etc/modprobe.conf ←修改相应配置文件,添加如下行到文尾:
aliasnet-pf-10off
aliasipv6off
[root@sample~]#shutdown-rnow ←重新启动系统,使设置生效
最后确认ipv6的功能已经被关闭。
[root@sample~]#ifconfig-a ←列出全部网络接口信息
eth0Linkencap:
EthernetHWaddr00:
0C:
29:
B6:
16:
A3
inetaddr:
192.168.0.13Bcast:
192.168.0.255Mask:
255.255.255.0
ine
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Centos 系统安全方面 系统安全 方面