useradd

How to Create A New User With Home Directory in Linux

 


 

Generally you have two users in your Linux after installation. The users are: root (super user) and your user. If you do not have graphical user interface then you need to do everything in the terminal. The useradd syntax works with root privileges. You can become root by typing the following commands:

  • su –
  • sudo su

 

Create a new user in Linux

If you are logged in as root then write the following:

useradd joe

 

If you are logged in as a user with “sudoers” privileges:

sudo useradd joe

 

With this method: the user is created without home directory.

Change joe to your user.

 

Create a new user with home directory in Linux

If you are logged in as root then write the following:

useradd -m -d /home/dirjoe joe

 

If you are logged in as a user with “sudoers” privileges:

sudo useradd -m -d /home/dirjoe joe

 

It will create a new user “joe” with his home directory in the following path: “/home/dirjoe”.

Change joe to your user and dirjoe to your desired folder.

 

Other related commands

 

Set password for Linux user

Type the following as root:

passwd joe

Change joe to your user.

 

Create a non-login user in Linux

Type the following as root:

useradd -M joe

usermod -L joe

-M ensures that no home directory will be created. -L locks the account.

Change joe to your user.

 

Delete a user in Linux

Type the following as root:

userdel joe

If you want to delete the user home directory then you have to do it manually.

Change joe to your user.

 

Delete a user with home directory in Linux

Type the following as root:

userdel -r joe

Change joe to your user.

 

How to exit from root in Linux

Type the following as root:

exit

Yes, it was easy 🙂

 

I’ve tested the commands on Ubuntu 14.04 LTS operating system.

 


 

Posted by:

Balazs Hende
I am a blogger and the founder of this site. I have started sparesome.com on October 1, 2013. Have a pleasant stay here!

Related articles

Categories

Back to Top