How to specify the home directory when creating a user in Linux?
To create a user and specify a home directory on Linux, you can use the useradd command with the -m option to create the home directory. The command to create a user “username” and specify a home directory is as follows:
sudo useradd -m -d /path/to/home/directory username
Replace /path/to/home/directory with the actual path of the specified home directory, and then replace username with the username of the user being created.
For instance, to create a user named John and set the home directory to /home/john, you can use the following command:
sudo useradd -m -d /home/john john
Next, you can use the passwd command to set a password for the newly created user.
sudo passwd john
Next, you can switch to the newly created user account using the su command.
su - john
This way, you can start using the new user account in the specified home directory.