首页 > 系统 > Linux > 正文

CentOS Linux服务器安全设置

2019-11-02 16:15:24
字体:
来源:转载
供稿:网友

我们必须明白:最小的权限+最少的服务=最大的安全

所以,无论是配置任何服务器,我们都必须把不用的服务关闭、把系统权限设置到最小话,这样才能保证服务器最大的安全。下面是CentOS服务器安全设置,供大家参考。

一、注释掉系统不需要的用户和用户组

注意:不建议直接删除,当你需要某个用户时,自己重新添加会很麻烦。

cp /etc/passwd /etc/passwdbak #修改之前先备份

vi /etc/passwd #编辑用户,在前面加上#注释掉此行

#adm:x:3:4:adm:/var/adm:/sbin/nologin

#lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

#sync:x:5:0:sync:/sbin:/bin/sync

#shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

#halt:x:7:0:halt:/sbin:/sbin/halt

#uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

#operator:x:11:0:operator:/root:/sbin/nologin

#games:x:12:100:games:/usr/games:/sbin/nologin

#gopher:x:13:30:gopher:/var/gopher:/sbin/nologin

#ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin #注释掉ftp匿名账号

cp /etc/group /etc/groupbak #修改之前先备份

vi /etc/group #编辑用户组,在前面加上#注释掉此行

#adm:x:4:root,adm,daemon

#lp:x:7:daemon,lp

#uucp:x:14:uucp

#games:x:20:

#dip:x:40:

二、关闭系统不需要的服务

service acpid stop chkconfig acpid off #停止服务,取消开机启动 #电源进阶设定,常用在 Laptop 上

service autofs stop chkconfig autofs off #停用自动挂载档桉系统与边装置

service bluetooth stop chkconfig bluetooth off #停用Bluetooth蓝芽

service cpuspeed stop chkconfig cpuspeed off #停用控制CPU速度主要用来省电

service cups stop chkconfig cups off #停用 Common UNIX Printing System 使系统支援印表机

service ip6tables stop chkconfig ip6tables off #禁止IPv6

####################################################################################################

如果要恢复某一个服务,可以执行下面操作

service acpid start chkconfig acpid on

三、禁止非root用户执行/etc/rc.d/init.d/下的系统命令

chmod -R 700 /etc/rc.d/init.d/*

chmod -R 777 /etc/rc.d/init.d/* #恢复默认设置

四、给下面的文件加上不可更改属性,从而防止非授权用户获得权限

chattr +i /etc/passwd

chattr +i /etc/shadow

chattr +i /etc/group

chattr +i /etc/gshadow

chattr +i /etc/services #给系统服务端口列表文件加锁,防止未经许可的删除或添加服务

lsattr /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/services #显示文件的属性

注意:执行以上权限修改之后,就无法添加删除用户了。

如果再要添加删除用户,需要先取消上面的设置,等用户添加删除完成之后,再执行上面的操作

chattr -i /etc/passwd #取消权限锁定设置

chattr -i /etc/shadow

chattr -i /etc/group

chattr -i /etc/gshadow

chattr -i /etc/services #取消系统服务端口列表文件加锁

现在可以进行添加删除用户了,操作完之后再锁定目录文件

五、限制不同文件的权限

chattr +a .bash_history #避免删除.bash_history或者重定向到/dev/null

chattr +i .bash_history

chmod 700 /usr/bin 恢复 chmod 555 /usr/bin

chmod 700 /bin/ping 恢复 chmod 4755 /bin/ping
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表