
usermodまたはgroupmodを使用して他の既存のグループにユーザーを追加することに違いがあるかどうか疑問に思います。例: Artists という補助グループがあり、このグループに Romeo を追加しようとしています。
usermod -G artists romeo
groupmod -U romeo artists
私はRed Hat 9を使用しています。
答え1
man
ページからgroupmod
:
The groupmod command modifies the definition of the specified GROUP
by modifying the appropriate entry in the group database.
オプションはありません-U
(2022年4月18日付Shadow-utils 4.6)。目的は、groupmod
メンバーの属性ではなくグループの属性を変更することです。
man
ページからusermod
:
-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
A list of supplementary groups which the user is also a member of ...
If the user is currently a member of a group which is not listed, the user
will be removed from the group. This behaviour can be changed via the -a
option, which appends the user to the current supplementary group list.
たとえば、ユーザーがromeo
すでにグループのメンバーである場合は、paintworkers
次のようにします。
usermod -G artists romeo
artists
彼はそのメンバーではなくサプリメントグループのメンバーですpaintworkers
。ただし、以下を使用する場合:
usermod -aG artists romeo
彼は2つのグループのメンバーになります。
修正する:
上記のように、これはshadow-utils
2022年4月18日4.6にも当てはまります。ただし、OPはshadow-utils
2021年2月12日4.9が現在以下を記録していると指摘しています-U
。
-U, --users
A list of usernames to add as members of the group.
したがって、おおよそのusermod -aG
またはgroupmod -U
フォーマットは将来のバージョンにも同じように適用する必要がありますshadow-utils
。
答え2
...木を通して森を見る
あなたが指しているすべてのことは最終的に起こるでしょう/etc/group
/etc/グループ形式
<groupname>:x:gid:user1,user2,user_n
x = パスワードフィールドはほとんど使用されず、/etc/passwd が /etc/shadow を参照するかのように /etc/gshadow を参照します。
gid = グループID、一意のグループID。ルールは、<未使用のシステムコンテンツ100個、管理コンテンツ1000個、その他のコンテンツ1000個です。 しかし、それについて私の言葉を引用しないでください。
グループ名のすべてのユーザーアカウントをカンマで区切ってグループに追加します。私は、ユーザーアカウントが属する補助グループを使用usermod
したり考慮したことがないと思います。正確に何が起こっているのかを確認するために、自分で編集する方が簡単で迅速で簡単なようです。groupmod
/etc/group
たぶん唯一のことメイングループ/etc/passwd
特定のユーザーアカウントに対して、各アカウントの4列目のgidで指定されます。ただし、ユーザーアカウントが属するすべてのセカンダリグループは、/etc/group
誰がどのグループのメンバーであるかを指定します。しかし、あなたはこれらのものを使うかusermod
単にgroupmod
変更するでしょう。
usermod -G
指定されたユーザーアカウント名は、/ etc / groupで指定されたグループ名のリストの末尾に追加されます。新しいグループにユーザーを追加する場合は、/etc/group を手動で編集する方が簡単です。そうしないと、5つ以上のグループに対して同時にこのコマンドを実行することが、/ etc / groupで手動で実行するよりも少し速くなる可能性があります。
groupmod -U
私はこれが有効なオプションだとは思いません(RHEL 7で)。
groupmod --help
Usage: groupmod [options] GROUP
Options:
-g, --gid GID change the group ID to GID
-h, --help display this help message and exit
-n, --new-name NEW_GROUP change the name to NEW_GROUP
-o, --non-unique allow to use a duplicate (non-unique) GID
-p, --password PASSWORD change the password to this (encrypted)
PASSWORD
-R, --root CHROOT_DIR directory to chroot into
-P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files