ユーザーとグループの管理:`useradd`、`usermod`、`groupadd`
Linuxマシンでユーザーアカウントやグループを作成、変更、削除する方法を学びます。
「ユーザーとグループの管理:`useradd`、`usermod`、`groupadd`」はCoddyKit上の無料Linux Command Line Masteryレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはLinux Command Line Mastery学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Linux Command Line Masteryコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Welcome to User Management
In Linux, managing users and groups is crucial for security and organization. Every file and process has an owner, and permissions are often set based on user and group affiliations.
This lesson will teach you how to create, modify, and remove user accounts and groups.
Creating New Users: `useradd`
The useradd command creates a new user account. By default, it creates a new primary group with the same name as the user and assigns a unique User ID (UID).
You'll often need sudo (superuser do) privileges to run this command.
sudo useradd newuserCustomizing Users: Home & Shell
When you create a user, you might want to specify their home directory and default shell. The -m option creates the user's home directory if it doesn't exist, and -s sets their login shell.
Without -m, no home directory is created, which can cause issues.
sudo useradd -m -s /bin/bash devuserVerifying User Details: `id`
After creating a user, you can verify their existence and check their User ID (UID) and Group IDs (GIDs) using the id command. This helps confirm the account was set up correctly.
id devuserUnderstanding Linux Groups
Groups are collections of users. They simplify permission management, allowing multiple users to share access to files and resources without individually setting permissions for each user.
Each user has a primary group (often named after the user) and can belong to multiple supplementary groups.
Creating New Groups: `groupadd`
To create a new group, you use the groupadd command. This is useful for organizing users into functional teams, like 'developers' or 'admins', and then assigning file permissions to that group.
sudo groupadd project_teamAdding Users to Groups: `usermod`
The usermod command modifies an existing user account. To add a user to a supplementary group, use the -aG (append to Group) option.
Remember, -a must be used with -G to append, otherwise -G alone would overwrite existing supplementary groups!
sudo usermod -aG project_team devuserModifying User Accounts: `usermod`
Beyond adding to groups, usermod can change various user properties. For example, you can change a user's primary group using -g or update their full name/comment using -c.
Always be careful when modifying user accounts, especially sensitive information.
sudo usermod -c "Developer for Project X" devuserRemoving Users and Groups
To remove a user account, use userdel. The -r option is commonly used to remove the user's home directory and mail spool along with the account.
To remove a group, use groupdel. A group cannot be removed if it's the primary group for any existing user.
sudo userdel -r olduser
sudo groupdel oldgroupQuick Check: User & Group Commands
Which of the following commands would you use to add an existing user named analyst1 to a new supplementary group named data_team?
Recap: User & Group Management
Congratulations! You've learned the essentials of user and group management in Linux.
useraddcreates new user accounts.groupaddcreates new groups.usermodmodifies existing user accounts and can add users to supplementary groups using-aG.userdelandgroupdelremove users and groups, respectively.
These commands are fundamental for system administration and maintaining a secure Linux environment.
よくある質問
「ユーザーとグループの管理:`useradd`、`usermod`、`groupadd`」レッスンは無料ですか?
はい。「ユーザーとグループの管理:`useradd`、`usermod`、`groupadd`」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Linux Command Line Masteryコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Linux Command Line Masteryコースには全4レッスンが含まれています。
「ユーザーとグループの管理:`useradd`、`usermod`、`groupadd`」で何を学びますか?
Linuxマシンでユーザーアカウントやグループを作成、変更、削除する方法を学びます。 ブラウザで直接実行するハンズオンコードでLinux Command Line Masteryを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Linux Command Line Masteryを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのLinux Command Line Masteryは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「ユーザーとグループの管理:`useradd`、`usermod`、`groupadd`」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このLinux Command Line Masteryレッスンでコードを書いて実行できますか?
はい。すべてのLinux Command Line Masteryレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- ユーザーとグループの管理:`useradd`、`usermod`、`groupadd`
- ネットワークコマンド入門:`ping`、`ip`、`netstat`
- 安全なリモートアクセス:`ssh`と`scp`
- chmod と chown によるファイル権限と所有権