DEV Community

Jeg
Jeg

Posted on

Create user in Linux and set its UID and home directory

To create a user named james and set its UID to 1859 and home directory to /var/www/james

By default useradd creates the user’s home directory in /home. If you want to create the user’s home directory in other location, use the d (--home) option.

On most Linux distributions, when creating a new user account with useradd, the user’s home directory is not created.

Use the -m (--create-home) option to create the user home directory as /home/username:

sudo useradd -m username

sudo useradd -u 1859 -m -d /var/www/james james

To verify id of an user
id -u username

To change after creating user
sudo usermod -u 1859 kirsty

Reference link: https://linuxize.com/post/how-to-create-users-in-linux-using-the-useradd-command/

Top comments (0)