在 一般情况下,一般用户通过执行“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: postmaster
postmaster: 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 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@www ~]# ifconfig -a ← 列出全部网络接口信息
sit0 Link encap:IPv6-in-IPv4 ← 确认ipv6是被启动的状态
[root@www ~]# vi /etc/modprobe.conf← 修改相应配置文件,添加如下行到文尾:
alias net-pf-10 off
alias 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 – Base
baseurl=http://mirrors.shlug.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=1
#released updates
[updates]
name=CentOS-$releasever – Updates
baseurl=http://mirrors.shlug.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=1
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever – Addons
baseurl=http://mirrors.shlug.org/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=0
#additional packages that may be useful
[extras]
name=CentOS-$releasever – Extras
baseurl=http://mirrors.shlug.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=0
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever – Plus
baseurl=http://mirrors.shlug.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=1
#contrib – packages by Centos Users
[contrib]
name=CentOS-$releasever – Contrib
baseurl=http://mirrors.shlug.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
protect=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
更新系统[root@www ~]#yum -y upgrade
一些安全的设置
1、用防火墙关闭不须要的任何端口,别人PING不到服务器,威胁自然减少了一大半
防止别人ping的方法:
1)命令提示符下打
echo 1 > /proc/sys/net/ipv4/icmp_ignore_all
2)用防火墙禁止(或丢弃) icmp 包
iptables -A INPUT -p icmp -j DROP
3)对所有用ICMP通讯的包不予响应
比如PING TRACERT
2、更改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 pppusers
4、更改下列文件权限,使任何人没有更改账户权限: chattr +i /etc/passwd chattr +i /etc/shadow chattr +i /etc/group chattr +i /etc/gshadow
5、chmod 600 /etc/xinetd.conf
centos 5.1下的安全设置(适合所有的linux版本)
2021-02-02 19:48CentOS教程网 Centos
因为root用户对系统具有全权的操作权限,为了避免一些失误的操作,建议在一般情况下,以一般用户登录系统,必要的时候需要root操作权限时,再通过“su -”命令来登录为root用户进行操作。
延伸 · 阅读
- 2021-02-03CentOS 5.1下跑Mono和Asp.net的实现方法
- 2021-02-02LINUX安全设置之关于GRUB加密图文教程全解
- 2021-02-02linux 服务器安全设置教程
- 2021-02-02centos 5 手动分区来安装系统的方法
- 2021-02-02CentOS 5.4 Kloxo安装详细说明
- 2021-02-02centos 安装免费控制面板kloxo步骤
- Centos
讲解RedHat系统中一些常用的重要内核文件
这篇文章主要介绍了RedHat系统中一些常用的重要内核文件,同时CentOS等RedHat系的Linux系统开发也可以参考,需要的朋友可以参考下...
- Centos
CentOS 清屏命令clear的讲解
今天小编为大家带来CentOS 清屏命令clear的讲解;希望可以帮助到大家,有需要的朋友一起去看看吧...
- Centos
详解yum命令之–showduplicates的使用方法
这篇文章主要介绍了详解yum命令之–showduplicates的使用方法,适用于RedHat系的Linux,需要的朋友可以参考下 ...
- Centos
Centos命令中nohup的用途的讲解
今天小编为大家带来的是Centos命令中nohup的用途的讲解;希望对大家会有帮助;有需要的朋友可以过来看看 ...
- Centos
CentOS6.9下svn快速安装配置方法
这篇文章主要为大家详细介绍了CentOS6.9下svn快速安装配置方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 ...
- Centos
CentOS下iptables封IP的命令讲解
今天小编为大家带来的是CentOS下iptables封IP的命令讲解!希望对大家会有帮助!有需要的朋友一起去看看吧...
- Centos
CentOS如何安装配置maven?
CentOS如何安装配置maven呢?下面小编将为大家带来的是CentOS安装配置maven的方法。希望能够帮助到大家,有需要的朋友一起去看看吧...
- Centos
CentOS如何查看当前系统下的gcc版本命令?
Linux系统下的Gcc是GNU推出的功能强大、性能优越的多平台编译器,是GNU的代表作品之一。今天小编为大家带来的是CentOS查看当前系统下的gcc版本命令的方法...