CentOS 7中系统安全及应用详述(4)

通过 su 命令可以非常方便地切换为另一个用户,但前提条件是必须知道目标用户的登录密码。对于生产环境中的 Linux 服务器,每多一个人知道特权密码,其安全风险也就增加一分。这个时候可以使用 sudo 命令就提升执行权限。不过,需要由管理员预先进行授权,指定允许哪些用户以超级用户(或其他普通用户)的身份来执行哪些命令。

在配置文件/etc/sudoers或visudo 中添加授权

授权记录的基本配置格式

用户 主机名列表=命令程序列表

用户:直接授权指定的用户名,或采用“%组名”的形式(授权一个组的所有用户)。
主机:使用此配置文件的主机名称。此部分主要是方便在多个主机间共用同一份 sudoers 文件,一般设为 localhost 或者实际的主机名即可。
命令:允许授权的用户通过 sudo 方式执行的特权命令,需填写命令程序的完整路径,多个命令之间以逗号“,”进行分隔。

首先我们先查看wheel组中的成员,然后用不在wheel组中的用户登录系统,来执行更改网络地址的指令,看是否能够更改。

[root@localhost ~]# vim /etc/group ...//省略部分内容... lp:x:7: mem:x:8: kmem:x:9: wheel:x:10:sun //只有sun一个用户 cdrom:x:11: mail:x:12:postfix man:x:15: dialout:x:18: ppy:x:19: ...//省略部分内容... [siti@localhost ~]$ ifconfig //查看网卡信息 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 49 bytes 7062 (6.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 86 bytes 9493 (9.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 ...//省略部分内容... [siti@localhost ~]$ ifconfig ens33 192.168.144.138 //更改ens33网卡IP地址 SIOCSIFADDR: 不允许的操作 //提示不允许操作 SIOCSIFFLAGS: 不允许的操作 [siti@localhost ~]$ sudo ifconfig ens33 192.168.144.138 //用sudo执行 [sudo] siti 的密码: siti 不在 sudoers 文件中。此事将被报告。 //不在sudo中,无法执行 [siti@localhost ~]$ ifconfig //查看网卡,看IP地址是否更改 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 27 bytes 5649 (5.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 89 bytes 9710 (9.4 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> ...//省略部分内容...

这个时候我们来在root用户来给siti用户添加授权条目

[root@localhost ~]# vim /etc/sudoers ...//省略部分内容... ## Sudoers allows particular users to run various commands as ## the root user, without needing the root password. #ar groups ## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname ## rather than USERALIAS # User_Alias ADMINS = jsmith, mikem siti localhost = /sbin/ifconfig //输入授权记录,注意:命令路径要写全 ## Command Aliases ...//省略部分内容... ## Installation and management of software # Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum ## Services @ @ :w! //强制保存,在输入:q退出

完成操作后注销系统,用siti用户登录,使用sudo提权再来更改IP地址,看是否可以更改。

[siti@localhost ~]$ sudo ifconfig ens33 192.168.144.138 //使用sudo命令提权执行命令 [sudo] siti 的密码: [siti@localhost ~]$ ifconfig //查看IP是否更改 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.138 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 445 bytes 39033 (38.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 ...//省略部分内容... //IP地址已更改 5、开关机安全控制

调整BIOS引导设置

将第一优先引导设备设为当前系统所在磁盘。

禁止其他设备引导系统,对应的设置项为“Disabled”。

将BIOS安全级别改为“setup”,并设置好管理密码,以防止未授权的修改。

限制更改GRUB引导参数

使用grub2-mkpasswd-pbkdf2生成密钥

修改/etc/grub.d/00_header文件中,添加密码记录

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/960b94ed28ea5d1b2e729797423d24df.html