The -m option in the useradd command is used to create a home directory for the new user. Here’s a detailed explanation of what this option does:
Functionality of the -m Option
-
Home Directory Creation:
- When you use the
-moption, theuseraddcommand automatically creates a home directory for the new user. The default location for this directory is typically/home/username, whereusernameis the name of the user being created.
- When you use the
-
Directory Structure:
- The home directory is set up with the appropriate ownership and permissions. By default, it is owned by the new user and has permissions set to
700(rwx------), meaning only the user has read, write, and execute permissions.
- The home directory is set up with the appropriate ownership and permissions. By default, it is owned by the new user and has permissions set to
-
Default Files:
- Depending on the system configuration, the home directory may also be populated with default configuration files (like
.bashrc,.profile, etc.) from a skeleton directory, usually located at/etc/skel. This provides the user with a basic setup for their environment.
- Depending on the system configuration, the home directory may also be populated with default configuration files (like
Example Usage
Here’s how you would use the -m option when creating a new user:
sudo useradd -m joker
In this example, a new user named joker will be created, and a home directory at /home/joker will be created for them.
Summary
The -m option is essential for ensuring that new users have a dedicated space to store their personal files and settings, making it a common practice when adding new users to a Linux system. If you have any more questions or need further clarification, feel free to ask!
