ホームページ  >  記事  >  システムチュートリアル  >  Linux のユーザーおよびユーザー グループ ファイルのアプリケーション システム設定

Linux のユーザーおよびユーザー グループ ファイルのアプリケーション システム設定

WBOY
WBOY転載
2024-04-05 09:10:02978ブラウズ

ID:ChinaUnix2013

1. User and user group files

In Linux, user accounts, user passwords, user group information and user group passwords are stored in different configuration files.

In the Linux system, the created user account and its related information (except password) are stored in the /etc/passwd configuration file. Because all users have read permissions on the passwd file, the password information is not saved in the file, but in the /etc/shadow configuration file.

In the passwd file, one line defines a user account. Each line is composed of multiple different arrays. The values ​​of each array are separated by ":". Each array represents a certain aspect of the account's information.

In the newly installed Linux system, the passwd configuration file already contains a lot of account information. These accounts are manually created by the system. They are the accounts that are required for the normal operation of the Linux process or some service programs. Linux course , the value of the last array of this kind of account is usually /sbin/nologin, which means that this account cannot be used to log in to the Linux system.

In the passwd configuration file, the corresponding relationship and meaning of each array from left to right:

Because passwd no longer saves password information, it is represented by x placeholder.

To prevent a user account from logging into Linux, just set the shell used by the user to /sbin/nologin. For example, for FTP accounts, usually only login and access to the FTP server are allowed, and login to the Linux operating system is not allowed. If a user does not have telnet permissions, that is, the user is not allowed to remotely log in and access the Linux operating system through telnet, just set the shell used by the user to /bin/true. If you want the user to not have telnet and ftp login permissions, you can set the user's shell to /bin/false.

In the /etc/shells file, if there is no /bin/true or /bin/false, you need to add it automatically:

[root@localhost~]#echo"/bin/false">>/etc/shells

[root@localhost~]#echo"/bin/true">>/etc/shells

2. User password file

For security reasons, the user's real password is encrypted using the MD5 encryption algorithm and stored in the /etc/shadow configuration file. This file can only be read by the root user.

Similar to the passwd file, the shadow file also defines and saves information related to an account per line. The first array is the user account name, and the second array is the account password.

3. User group account file

User group account information is stored in the /etc/group configuration file What is the Linux system user configuration file?, any user can read it. The real password of the user group is stored in the /etc/gshadow configuration file.

In group, the first array represents the name of the user group, the second array is x, the third is the ID number of the user group, and the fourth is the list of user members of the user group. Between each user name Separate with colons.

4. Add user

To create or add a new user, use the useradd command. The command usage is:

useradd[option]username

用户配置文件有()版本_linux系统用户配置文件是什么?_用户配置文件的类型

This command has many options, the commonly used ones are:

-cComment user sets the comment description text for the account

-d home directory specifies the home directory to replace the default /home/username

-mIf the home directory does not exist, create it. -r combined with -m creates a home directory for the system account

-MDo not create home directory

-edate specifies the date the account will expire. The date format is MM/DD/YY

-fdays account will be permanently suspended after a few days of expiration. If it is specified as -, it will be suspended immediately. If it is -1, this function will be turned off

-gUser group specifies which user group to add the user to. The user group must exist

-GUser group list specifies the list of user groups that the user joins at the same time. Each group is separated by commas

-nDo not create private user groups for users

-sshell specifies the shell used when the user logs in, the default is /bin/bash

-rCreate a system account with a user ID greater than 500, and the corresponding home directory will not be created by default

-uUser ID automatically specifies the ID value of the new user, which must be unique and less than 499

-ppassword specifies the login password for the new user. The password here is the password value obtained after MD5 encryption of the corresponding login password, which does not match the original text of the real password. Therefore, in actual applications, this parameter option is rarely used, and the passwd command is generally used alone to set the login password for the user.

Example:

To create a user named nisj as a member of the babyfish user group, the operation command is:

[root@localhost~]#useradd-gbabyfishnisj

[root@localhost~]#idnisj

uid=502(nisj)gid=500(babyfish)groups=500(babyfish)

[root@localhost~]#tail-1/etc/passwd

nisj:x:502:500::/home/nisj:/bin/bash

When adding a user, if the user group is not specified with the -g parameter, the system will manually create a private user group with the same name as the user account by default. If you do not need to create this private user group, you can use the -n parameter.

For example, if you add an account named nsj820 but do not specify a user group, the operation result is:

[root@localhost~]#useraddnsj820

[root@localhost~]#idnsj820

uid=503(nsj820)gid=503(nsj820)groups=503(nsj820)

[root@localhost~]#tail-1/etc/passwd

nsj820:x:503:503::/home/nsj820:/bin/bash

[root@localhost~]#tail-2/etc/passwd

nisj:x:502:500::/home/nisj:/bin/bash

nsj820:x:503:503::/home/nsj820:/bin/bash#システムは、ID 番号 503 を持つ nsj820 という名前のユーザー グループを手動で作成しました

ユーザー アカウントを作成するとき、システムはユーザーに対応するホーム ディレクトリを手動で作成します。このディレクトリは、デフォルトでは /home ディレクトリに配置されます。場所を変更したい場合は、-d オプションを使用して指定できます。パラメータ; ユーザーがログインするために使用するシェルのデフォルトは /bin/bash です。これを変更する場合は、-s パラメータを使用して

を指定します

たとえば、vodup という名前のアカウントを作成し、ホーム ディレクトリを /var ディレクトリに配置し、ログイン シェルを /sbin/nologin に指定する場合、操作コマンドは次のようになります。

[root@localhost~]#useradd-d/var/vodup-s/sbin/nologinvodup

[root@localhost~]#idvodup

uid=504(vodup)gid=504(vodup)グループ=504(vodup)

[root@localhost~]#tail-1/etc/passwd

vodup:x:504:504::/var/vodup:/sbin/nologin

[root@localhost~]#tail-1/etc/group

vodup:x:504:

5. アカウント属性の設定

作成したユーザーの場合、usermod コマンドを使用して、ログイン名、ホーム ディレクトリ、ユーザー グループ、ログイン シェルなどを含むアカウントのさまざまな属性を変更および設定できます。このコマンドの使用方法は次のとおりです。

usermod[オプション]ユーザー名

いくつかのオプション

(1)ユーザーアカウント名の変更

これを実現するには -l パラメータを使用します。コマンドの使用法は次のとおりです:

usermod-l新しいユーザー名元のユーザー名

たとえば、ユーザー nsj820 の名前を nsj0820 に変更する場合、操作コマンドは次のとおりです。

[root@localhost~]#usermod-lnsj0820nsj820

[root@localhost~]#idnsj0820

uid=503(nsj0820)gid=503(nsj820)グループ=503(nsj820)

[root@localhost~]#tail-1/etc/passwd

nsj0820:x:503:503::/home/nsj820:/bin/bash

出力から、ユーザー名が nsj0820 に変更されたことがわかります。ホーム ディレクトリは元の /home/nsj820 のままです。/home/nsj0820

Linux システム ユーザー設定ファイルとは何ですか?

に変更したい場合は、次のコマンドを実行することで変更できます [root@localhost~]#usermod-d/home/nsj0820nsj0820

[root@localhost~]#idnsj0820

uid=503(nsj0820)gid=503(nsj820)グループ=503(nsj820)

[root@localhost~]#tail-1/etc/passwd

nsj0820:x:503:503::/home/nsj0820:/bin/bash

[root@localhosthome]#mv/home/nsj820/home/nsj0820

(2)アカウントをロックする

ユーザーのログインを一時的に禁止したい場合は、ユーザー アカウントをロックできます。アカウントをロックするには、-L パラメーターを使用します。コマンドの使用法は次のとおりです:

usermod-Lロックされるアカウント

Linux は、パスワード ファイル シャドウのパスワード配列の前に「!」を追加してユーザーをロックし、ユーザーがロックされていることを示します。

[root@localhosthome]#usermod-Lnsj0820

[root@localhosthome]#tail-1/etc/shadow

nsj0820:!$1$JEW25RtU$X9kIdwJi/HPzSKMVe3EK30:16910:0:99999:7:::

ただし、root ユーザーから入って、ロックされたユーザーに su することはできます。

(3)アカウントのロックを解除する

アカウントのロックを解除するには、usermod コマンドに -U パラメーターを指定して使用します。

[root@localhost~]#usermod-Unsj0820

[root@localhost~]#tail-1/etc/shadow

nsj0820:$1$JEW25RtU$X9kIdwJi/HPzSKMVe3EK30:16910:0:99999:7:::

6. アカウントを削除します

アカウントを削除するには、userdel コマンドを使用できます。その使用法は次のとおりです:

userdel[-r]アカウント名

-r はオプションです。このパラメータを指定すると、アカウントの削除と同時に、そのアカウントに対応するホーム ディレクトリも削除されます。

[root@localhost~]#userdel-rnsj0820

すべてのユーザー アカウントのパスワードの有効期限を設定するには、/etc/login.defs 構成ファイルの PASS_MAX_DAYS 構成項目の値を変更できます。デフォルト値は 99999 で、ユーザー アカウントのパスワードは無期限になります。 。 PASS_MIN_LEN 構成項目は、アカウント パスワードの最小幅を指定するために使用されます。デフォルトは 5 文字です。

7. ユーザーのログインパスワードを設定します

passwd コマンドを使用して設定します。コマンドの使用法は次のとおりです:

passwd[アカウント名]

アカウント名を指定した場合は、指定したアカウントのログインパスワードが設定され、元のパスワードが手動で上書きされます。 root ユーザーのみが、指定されたアカウントのパスワードを設定する権限を持っています。通常、ユーザーは自分のアカウントのパスワードのみを設定または変更できます (パラメータなし)。

たとえば、nisj アカウントのログインパスワードを設定する場合、運用コマンドは次のようになります。

用户配置文件的类型_linux系统用户配置文件是什么?_用户配置文件有()版本

[root@localhosthome]#passwdnisj

usernisj.

のパスワードの変更 ###新しいパスワード:###

BADPASSWORD:istooshort

悪いパスワード:istoosimple

###新しいパスワード再入力:###

passwd:alauthenticationトークンが正常に更新されました。

アカウントのログインパスワードを設定すると、そのアカウントはシステムにログインできるようになります。

8. アカウント パスワードのロック/ロック解除、パスワード ステータスの照会、アカウント パスワードの削除

LINUX では、ディレクトリを削除すると、ユーザー アカウントがロックされるだけでなく、アカウントのパスワードもロックされる可能性があり、どちらかがロックされると、システムにログインできなくなります。 root ユーザーのみがこのコマンドを実行する権限を持っています。アカウントのパスワードをロックするには、passwd コマンドに -l オプションを付けて使用します。その使用法は次のとおりです:

パスワードアカウント名

passwd-uaccountname#アカウントのパスワードのロックを解除する

[root@localhosthome]#passwd-lnisj

usernisj.

のロックパスワード

passwd:成功

[root@localhosthome]#passwd-unisj

usernisj のパスワードのロックを解除します。

passwd:成功

現在のアカウントのパスワードがロックされているかどうかを確認するには、passwd コマンドに -S パラメーターを指定して使用します。その使用法は次のとおりです。

passwd-S アカウント名

###例えば###

[root@localhosthome]#passwd-Snisj

以上がLinux のユーザーおよびユーザー グループ ファイルのアプリケーション システム設定の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はitcool.netで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。