Linux の既存グループにユーザーを追加する

Linux の既存グループにユーザーを追加する

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-utils2022年4月18日4.6にも当てはまります。ただし、OPはshadow-utils2021年2月12日4.9が現在以下を記録していると指摘しています-U

       -U, --users
           A list of usernames to add as members of the group.

したがって、おおよそのusermod -aGまたはgroupmod -Uフォーマットは将来のバージョンにも同じように適用する必要がありますshadow-utils

おすすめ記事