现象演示:
[www@localhost etc]$ useradd tester1
bash: /usr/sbin/useradd: Permission denied
解决方案:
1、在useradd命令前添加sudo命令。(若还是失败,情形如下图,则转向步骤2)
[www@localhost etc]$ sudo useradd tester1
[sudo] password for www:
www is not in the sudoers file. This incident will be reported.
2、切换到root用户(su root)
①首先给sudoers文件添加write权限。(chmod u+w sudoers)
[root@localhost etc]# ls -l | grep sudoers
-r--r-----. 1 root root 4328 Oct 30 2018 sudoers
drwxr-x---. 2 root root 6 Oct 30 2018 sudoers.d
[root@localhost etc]# chmod u+w sudoers
[root@localhost etc]# ls -l | grep sudoers
-rw-r-----. 1 root root 4328 Oct 30 2018 sudoers
drwxr-x---. 2 root root 6 Oct 30 2018 sudoers.d
②再使用vi??/etc/sudoers 命令添加普通用户的操作权限。
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
www ALL=(ALL) ALL ## 添加此行
3、切换回普通用户
4、再使用命令 sudo useradd tester1即可运行成功,并在/etc/passwd中查看此用户。
[www@localhost etc]$ sudo useradd tester1
[sudo] password for www:
[www@localhost etc]$
[www@localhost etc]$ tail /etc/passwd
setroubleshoot:x:990:984::/var/lib/setroubleshoot:/sbin/nologin
saned:x:989:983:SANE scanner daemon user:/usr/share/sane:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:988:982::/run/gnome-initial-setup/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
www:x:1000:1000:www:/home/www:/bin/bash
tester1:x:1001:1001::/home/tester1:/bin/bash
|