usermod说账户不存在,但adduser说存在。

我运行这个命令
usermod -a -G dialout amashreghi

但是我发现amashreghi不存在,然而,当我尝试使用adduser命令添加用户时。
adduser amashreghi

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

amashreghi 有密码吗? - George Udosen
是的,我是sudo用户,但不是root用户。虽然我也尝试过使用sudo进行usermod操作。 - A. Mashreghi
4个回答

要直接编辑/etc/group,请使用vigr
来自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

如果你正在使用newgrp进行这个操作,可能需要执行sudo grpconv命令! - Nishant

试一试这个。 (我假设你已经准备好删除与该用户相关的所有内容并重新开始,如果没有,请不要运行这些命令。)
userdel -r amashreghi
grep amashreghi /etc/passwd

如果第二个命令有返回内容,运行以下命令:
sudo -H gedit /etc/passwd

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

这对我有效:
sudo usermod -aG dialout amashreghi

只要这样做:
sudo vim /etc/group

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

somegroup:x:25:yourusername

3不建议使用Vim编辑组文件:请参考https://unix.stackexchange.com/a/79177/262708 - abu_bua