适合所有的linux版本-centos-5.1下的安全设置

技术教程 2026-01-08 14:47:35 浏览
安全设置

在 一般情况下,一般用户通过执行“su -”命令、输入正确的root密码,可以登录为root用户来对系统进行管理员级别的配置。但是,为了更进一步加强系统的安全性,有必要建立一个管理员的 组,只允许这个组的用户来执行“su -”命令登录为root用户,而让其他组的用户即使执行“su -”、输入了正确的root密码,也无法登录为root用户。在UNIX下,这个组的名称通常为“wheel”。首先我们创建两个普通的用户tom john[root@www ~]# useradd tom[root@www ~]# passwd tom输入你的密码[root@www ~]# useradd john[root@www ~]# passwd john输入你的密码[root@www ~]# usermod -g wheel tom 将tom用户加入到wheel组中[root@www ~]# vi /etc/pam.d/su← 打开这个配置文件找到这句话在第六行将其前面的#注释掉# auth required pam_wheel.so use_uid[root@www ~]# echo “SU_WHEEL_ONLY yes” >> /etc/login.defs然后你可以分别用tom和john登陆,没有加入到wheel组的用户,执行“su -”命令,即使输入了正确的root密码,也无法登录为root用户在系统出现错误或有重要通知发送邮件给root的时候,让系统自动转送到我们通常使用的邮箱中,这样方便查阅相关报告和日志。[root@www ~]# vi /etc/aliases在这两句下面mailer-daemon: postmasterpostmaster: root加入这句话root: zy66289214@126.com 这里写自己邮箱[root@www ~]# newaliases 重建aliasesdb[root@www ~]# echo test | mail root 发送测试软件给root[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 Linuxbaseurl=$releasever/en/$basearch/daggpgcheck=1enabled=1[root@sample ~]# rpm –import← 导入非官方库的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@www ~]# ifconfig -a ← 列出全部网络接口信息sit0 Link encap:IPv6-in-IPv4 ← 确认ipv6是被启动的状态[root@www ~]# vi /etc/modprobe.conf← 修改相应配置文件,添加如下行到文尾:alias net-pf-10 offalias ipv6 off[root@www ~]# shutdown -r now← 重新启动系统,使设置生效修改/etc/yum.repos.d/CentOS-Base.repo,将镜象站点地址改为在中国的镜象站点地址。不然我们通过yum安装软件速度会极慢。修改如下# CentOS-Base.repo## This file uses a new mirrorlist system developed by Lance Davis for CentOS.# The mirror system uses the connecting IP address of the client and the# update status of each mirror to pick mirrors that are updated to and# geographically close to the client. You should use this for CentOS updates# unless you are manually picking other mirrors.## If the mirrorlist= does not work for you, as a fall back you can try the# remarked out baseurl= line instead.##[base]name=CentOS-$releasever – Basebaseurl=$releasever/os/$basearch/gpgcheck=1gpgkey=updates[updates]name=CentOS-$releasever – Updatesbaseurl=$releasever/updates/$basearch/gpgcheck=1gpgkey=used/produced in the build but not released[addons]name=CentOS-$releasever – Addonsbaseurl=$releasever/addons/$basearch/gpgcheck=1gpgkey=packages that may be useful[extras]name=CentOS-$releasever – Extrasbaseurl=$releasever/extras/$basearch/gpgcheck=1gpgkey=packages that extend functionality of existing packages[centosplus]name=CentOS-$releasever – Plusbaseurl=$releasever/centosplus/$basearch/gpgcheck=1enabled=0gpgkey=– packages by Centos Users[contrib]name=CentOS-$releasever – Contribbaseurl=$releasever/contrib/$basearch/gpgcheck=1enabled=0protect=0gpgkey=更新系统[root@www ~]#yum -y upgrade一些安全的设置1、用防火墙关闭不须要的任何端口,别人PING不到服务器,威胁自然减少了一大半防止别人ping的方法:1)命令提示符下打echo 1 > /proc/sys/net/ipv4/icmp_ignore_all2)用防火墙禁止(或丢弃) icmp 包ipTables -A INPUT -p icmp -j DROP3)对所有用ICMP通讯的包不予响应比如PING TRACERT2、更改SSH端口,最好改为10000以上,别人扫描到端口的机率也会下降vi /etc/ssh/sshd_config将PORT改为1000以上端口同时,创建一个普通登录用户,并取消直接root登录useradd ‘username'passwd ‘username'vi /etc/ssh/sshd_config在最后添加如下一句:PermitRootLogin no #取消root直接远程登录3、删除系统臃肿多余的账号: userdel adm userdel lp userdel sync userdel shutdown userdel halt userdel news userdel uucp userdel operator userdel games userdel gopher userdel ftp 如果你不允许匿名FTP,就删掉这个用户帐号 groupdel adm groupdel lp groupdel news groupdel uucp groupdel games groupdel dip groupdel pppusers4、更改下列文件权限,使任何人没有更改账户权限: chattr +i /etc/passwd chattr +i /etc/shadow chattr +i /etc/group chattr +i /etc/gshadow5、chmod 600 /etc/xinetd.conf

本文版权声明本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请联系本站客服,一经查实,本站将立刻删除。

发表评论

热门推荐