CentOS系统安装配置

chao 2022-5-13 15:17 CentOS&Ubuntu 抢沙发 581IT人生
一、注释掉系统不需要的用户和用户组
注意:不建议直接删除,当你需要某个用户时,自己重新添加会很麻烦。
   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/*    #恢复默认设置
  系统运维  www.osyunwei.com  温馨提醒:qihang01原创内容©版权所有,转载请注明出处及原文链接
四、给下面的文件加上不可更改属性,从而防止非授权用户获得权限
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
chmod 700 /usr/bin/vim         恢复  chmod 755 /usr/bin/vim
chmod 700 /bin/netstat          恢复  chmod 755 /bin/netstat
chmod 700 /usr/bin/tail          恢复  chmod 755 /usr/bin/tail
chmod 700 /usr/bin/less         恢复  chmod 755 /usr/bin/less
chmod 700 /usr/bin/head       恢复  chmod 755 /usr/bin/head
chmod 700 /bin/cat                恢复  chmod 755 /bin/cat
chmod 700 /bin/uname          恢复  chmod 755 /bin/uname
chmod 500 /bin/ps                 恢复  chmod 755 /bin/ps
六、禁止使用Ctrl+Alt+Del快捷键重启服务器
cp /etc/inittab  /etc/inittabbak
vi /etc/inittab    #注释掉下面这一行
#ca::ctrlaltdel:/sbin/shutdown -t3 -r now
七、使用yum update更新系统时不升级内核,只更新软件包
由于系统与硬件的兼容性问题,有可能升级内核后导致服务器不能正常启动,这是非常可怕的,没有特别的需要,建议不要随意升级内核。
cp /etc/yum.conf    /etc/yum.confbak
1、修改yum的配置文件 vi /etc/yum.conf  在[main]的最后添加 exclude=kernel*
2、直接在yum的命令后面加上如下的参数:
yum --exclude=kernel* update
查看系统版本  cat /etc/issue
查看内核版本  uname -a
八、关闭Centos自动更新
chkconfig --list yum-updatesd  #显示当前系统状态
yum-updatesd    0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
service yum-updatesd stop      #关闭 
正文部分到此结束

版权声明:除非注明,本文由( chao )原创,转载请保留文章出处

本文链接:CentOS系统安装配置

继续浏览:安全 优化

分享文章:QQ空间腾讯微博新浪微博网易微博人人网开心网腾讯朋友百度搜藏

iptables限制地址访问
腾讯云Linux维护命令