为了提高安全性,可禁止root帐号通过SSH登录。此时要远程管理系统,就要建立另一个管理帐号。
使用root登录系统,创建一个新用户,并设置新用户的密码
[root@ali_abc ~]# useradd abc [root@ali_abc ~]# passwd abc Changing password for user abc. New password: Retype new password: passwd: all authentication tokens updated successfully.
以新建的用户登录系统,尝试做更新操作
[abc@ali_abc ~]$ sudo yum update
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for abc:
abc is not in the sudoers file. This incident will be reported.
[abc@ali_abc ~]$
#提示“abc is not in the sudoers file”,新用户无法执行sudo命令。
再次以root用户登录系统,将新建用户加入/etc/sudoers
[root@ali_abc ~]# ll /etc/sudoers -r--r----- 1 root root 3957 Apr 24 23:20 /etc/sudoers [root@ali_abc ~]# chmod +w /etc/sudoers #/etc/sudoers文件是只读的,要临时给文件加上写权限 [root@ali_abc ~]# ll /etc/sudoers -rw-r----- 1 root root 3957 Apr 24 23:20 /etc/sudoers [root@ali_abc ~]# vim /etc/sudoers root ALL=(ALL) ALL abc ALL=(ALL) ALL [root@ali_abc ~]# chmod -w /etc/sudoers [root@ali_abc ~]# ll /etc/sudoers -r--r----- 1 root root 3957 Apr 24 23:20 /etc/sudoers #修改/etc/sudoers后,将读权限取消
也可以用下面的方法让新用户可以执行sudo
[root@ali_abc ~]# usermod -aG wheel abc
再次以新用户身份执行sudo进行测试
[abc@ali_abc ~]$ sudo yum update
#以新建的用户登录系统,可以做升级操作
如果有需要,可以从一般帐号切换到root帐号
[abc@ali_abc ~]$ su - root Password: #输入root帐号的密码,- 的作用是切换到root帐号,同时加载root帐号的配置 Last login: Tue Apr 24 23:22:38 CST 2018 on pts/0 [root@ali_abc ~]# pwd /root [root@ali_abc ~]#
文章评论