usermod 说帐户不存在,但 adduser 说帐户存在

usermod 说帐户不存在,但 adduser 说帐户存在

我运行命令

usermod -a -G dialout amashreghi

但是当我尝试使用 adduser 添加用户时,却发现 amashreghi 不存在

adduser amashreghi

它说 amashreghi 已经存在。发生了什么事?!

答案1

直接编辑/etc/group使用维格尔

man vigr

NAME
       vipw, vigr - edit the password, group, shadow-password or shadow-group file

SYNOPSIS
       vipw [options]

       vigr [options]

DESCRIPTION
       The vipw and vigr commands edits the files /etc/passwd and /etc/group, respectively. With the -s flag,
       they will edit the shadow versions of those files, /etc/shadow and /etc/gshadow, respectively. The
       programs will set the appropriate locks to prevent file corruption. When looking for an editor, the
       programs will first try the environment variable $VISUAL, then the environment variable $EDITOR, and
       finally the default editor, vi(1).

因此,你可以/etc/group使用以下命令编辑文件

sudo vigr

组条目的格式可以在 man 中找到。来自man group

NAME
       group - user group file

DESCRIPTION
       The  /etc/group file is a text file that defines the groups on the system.  There is one entry per line,
       with the following format:

           group_name:password:GID:user_list

       The fields are as follows:

       group_name  the name of the group.

       password    the (encrypted) group password.  If this field is empty, no password is needed.

       GID         the numeric group ID.

       user_list   a list of the usernames that are members of this group, separated by commas.

FILES
       /etc/group

答案2

试试看。(我假设您已准备好删除与此用户相关的所有内容并重新开始,如果您还没有准备好,请不要运行这些。)

userdel -r amashreghi
grep amashreghi /etc/passwd

如果第二条命令返回任何内容,请运行:

sudo -H gedit /etc/passwd

删除以 开头的行amashreghi,然后保存文件。现在尝试再次添加用户。

答案3

这对我有用:

sudo usermod -aG dialout amashreghi

答案4

只要这样做:

sudo vim /etc/group

并将您的姓名添加到所需的组,例如:

somegroup:x:25:yourusername

相关内容