That's a very practical question! While useradd -m is convenient, knowing how to do it manually is super useful.
To manually create a home directory, you generally follow these steps:
Create the directory: Use
mkdirto create the directory itself. For example, for a user namedcharlie:sudo mkdir /home/charlieSet ownership: The home directory needs to be owned by the user it belongs to. Use
chownto change the ownership.sudo chown charlie:charlie /home/charlie(This assumes the user
charlieand a groupcharliealready exist. If only the user exists, you might just dochown charlie /home/charlieorchown charlie:users /home/charliedepending on your system's group strategy.)Set permissions: Assign appropriate permissions so the user can read, write, and execute (access) files within their own home directory, and others have limited or no access. A common set of permissions for a home directory is
700or750.sudo chmod 700 /home/charlie700means only the owner (charlie) has full read, write, and execute permissions.750means the owner (charlie) has full permissions, and the group (charlie) has read and execute permissions, but no others can access it.
So, for a new user named charlie (assuming you've already created the user account without a home directory first, e.g., sudo useradd charlie), the full manual process would look like this:
sudo mkdir /home/charlie
sudo chown charlie:charlie /home/charlie
sudo chmod 700 /home/charlie
After these steps, charlie would have a proper home directory!
Do you want to try creating a user and their home directory manually?