Linux-admin-user-management

提供:Dev Guides
移動先:案内検索

Linux Admin-ユーザー管理

_user_管理を議論するとき、理解する3つの重要な用語があります-

  • ユーザー
  • グループ
  • 許可

ファイルとフォルダーに適用される詳細なアクセス許可については既に説明しました。 この章では、ユーザーとグループについて説明します。

CentOSユーザー

CentOSでは、2種類のアカウントがあります-

  • システムアカウント-デーモンまたはその他のソフトウェアに使用されます。
  • インタラクティブアカウント-通常、システムリソースにアクセスするためにユーザーに割り当てられます。

2つのユーザータイプの主な違いは-

  • *システムアカウント*は、ファイルとディレクトリにアクセスするためにデーモンによって使用されます。 これらは通常、シェルまたは物理的なコンソールログインを介した対話型ログインを許可されません。
  • *インタラクティブアカウント*は、シェルまたは物理コンソールログインからコンピューティングリソースにアクセスするためにエンドユーザーによって使用されます。

このユーザーの基本的な理解を踏まえて、会計部門のボブ・ジョーンズの新しいユーザーを作成しましょう。 adduser コマンドを使用して、新しいユーザーを追加します。

以下は、いくつかの adduser 共通スイッチです-

Switch Action
-c Adds comment to the user account
-m Creates user home directory in default location, if nonexistent
-g Default group to assign the user
-n Does not create a private group for the user, usually a group with username
-M Does not create a home directory
-s Default shell other than/bin/bash
-u Specifies UID (otherwise assigned by the system)
-G Additional groups to assign the user to

新しいユーザーを作成するときは、次のように_-c、-m、-g、-n_スイッチを使用します-

[root@localhost Downloads]# useradd -c "Bob Jones  Accounting Dept Manager"
-m -g accounting -n bjones

次に、新しいユーザーが作成されたかどうかを確認しましょう-

[root@localhost Downloads]# id bjones
(bjones) gid = 1001(accounting) groups = 1001(accounting)

[root@localhost Downloads]# grep bjones/etc/passwd
bjones:x:1001:1001:Bob Jones  Accounting Dept Manager:/home/bjones:/bin/bash

[root@localhost Downloads]#

今、私たちはpasswdコマンドを使用して新しいアカウントを有効にする必要があります-

[root@localhost Downloads]# passwd bjones
Changing password for user bjones.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

[root@localhost Downloads]#

ユーザーアカウントが有効になっていないため、ユーザーはシステムにログインできません。

ユーザーアカウントを無効にする

システムでアカウントを無効にする方法はいくつかあります。 これらは、/etc/passwdファイルを手動で編集することから始まります。 または、passwd_コマンドと* '- l _ *スイッチを使用します。 どちらの方法にも大きな欠点が1つあります。ユーザーが_ssh_アクセス権を持ち、認証にRSAキーを使用する場合、この方法を使用してログインできます。

次に、_chage_コマンドを使用して、パスワードの有効期限を前の日付に変更します。 また、無効にした理由をアカウントに書き留めておくこともできます。

[root@localhost Downloads]# chage -E 2005-10-01 bjones

[root@localhost Downloads]# usermod  -c "Disabled Account while Bob out of the country
for five months" bjones

[root@localhost Downloads]# grep bjones/etc/passwd
bjones:x:1001:1001:Disabled Account while Bob out of the country for four
months:/home/bjones:/bin/bash

[root@localhost Downloads]#

グループを管理する

Linuxでグループを管理すると、管理者がコンテナー内のユーザーを結合して、すべてのグループメンバーに適用できる権限セットを適用するのが便利になります。 たとえば、経理部門のすべてのユーザーが同じファイルにアクセスする必要がある場合があります。 したがって、会計ユーザーを追加して、会計グループを作成します。

ほとんどの場合、特別な権限を必要とするものはすべてグループで行う必要があります。 このアプローチは、通常、1人のユーザーだけに特別な許可を適用するよりも時間を節約します。 たとえば、Sallyはレポートを担当しており、Sallyのみがレポートのために特定のファイルにアクセスする必要があります。 しかし、サリーがいつか病気になり、ボブが報告した場合はどうなりますか? または、レポートの必要性が高まりますか? グループが作成されると、管理者は一度だけそれをする必要があります。 ユーザーの追加は、ニーズの変化または拡大に応じて適用されます。

以下は、グループの管理に使用されるいくつかの一般的なコマンドです-

  • chgrp

  • groupadd

  • グループ

  • usermod

    *chgrp* -ファイルまたはディレクトリのグループ所有権を変更します。

会計グループの人々がファイルを保存し、ファイル用のディレクトリを作成するためのディレクトリを作成しましょう。

[root@localhost Downloads]# mkdir/home/accounting

[root@localhost Downloads]# ls -ld/home/accounting
drwxr-xr-x. 2 root root 6 Jan 13 10:18/home/accounting

[root@localhost Downloads]#

次に、_group_ownership_を_accounting_グループに与えましょう。

[root@localhost Downloads]# chgrp -v  accounting/home/accounting/
changed group of ‘/home/accounting/’ from root to accounting

[root@localhost Downloads]# ls -ld/home/accounting/
drwxr-xr-x. 2 root accounting 6 Jan 13 10:18/home/accounting/

[root@localhost Downloads]#

これで、アカウンティンググループの全員が_/home/accounting_に対する_read_および_execute_権限を持ちます。 書き込み権限も必要になります。

[root@localhost Downloads]# chmod g+w/home/accounting/

[root@localhost Downloads]# ls -ld/home/accounting/
drwxrwxr-x. 2 root accounting 6 Jan 13 10:18/home/accounting/

[root@localhost Downloads]#

_accounting group_は機密文書を処理する可能性があるため、_other_または_world_にいくつかの制限付きアクセス許可を適用する必要があります。

[root@localhost Downloads]# chmod o-rx/home/accounting/

[root@localhost Downloads]# ls -ld/home/accounting/
drwxrwx---. 2 root accounting 6 Jan 13 10:18/home/accounting/

[root@localhost Downloads]#
*groupadd* -新しいグループを作成するために使用されます。
Switch Action
-g Specifies a GID for the group
-K Overrides specs for GID in/etc/login.defs
-o Allows overriding non-unique group id disallowance
-p Group password, allowing the users to activate themselves

secretという新しいグループを作成しましょう。 グループにパスワードを追加し、ユーザーが既知のパスワードで自分自身を追加できるようにします。

[root@localhost]# groupadd secret

[root@localhost]# gpasswd secret
Changing the password for group secret
New Password:
Re-enter new password:

[root@localhost]# exit
exit

[centos@localhost ~]$ newgrp secret
Password:

[centos@localhost ~]$ groups
secret wheel rdc

[centos@localhost ~]$

実際には、グループのパスワードはあまり使用されません。 セカンダリグループは適切であり、他のユーザー間でパスワードを共有することはセキュリティ上の優れた慣行ではありません。

*groups* コマンドは、ユーザーが属するグループを表示するために使用されます。 現在のユーザーにいくつかの変更を加えた後、これを使用します。
*usermod* は、アカウント属性を更新するために使用されます。

一般的な_usermod_スイッチは次のとおりです。

Switch Action
-a Appends, adds user to supplementary groups, only with the -G option
-c Comment, updatesthe user comment value
-d Home directory, updates the user’s home directory
-G Groups, adds or removesthe secondary user groups
-g Group, default primary group of the user
[root@localhost]# groups centos
centos : accounting secret

[root@localhost]#

[root@localhost]# usermod -a -G wheel centos

[root@localhost]# groups centos
centos : accounting wheel secret

[root@localhost]#