How to create a user in Linux?

To create a user on Linux, you can use the following command:

  1. create a new user
sudo adduser username

Replace “username” with the desired username.

  1. create a new user
sudo useradd username

Replace “username” with the desired username that you wish to create.

  1. Specify user home directory when creating a user.
sudo useradd -m -s /bin/bash username

The -m option automatically creates the user’s home directory when creating a user, while the -s option specifies the user’s default shell as /bin/bash.

  1. Specify user groups when creating users.
sudo useradd -g groupname username

Replace ‘groupname’ with the name of the user group to be assigned to the new user.

  1. Create a password when setting up a user account.
sudo passwd username

Replace “username” with the username for which you want to set a password. You will then be prompted to enter and confirm the password.

Note: The above command needs to be executed with administrator privileges (sudo).

bannerAds