Suppose you have already installed the Ubuntu desktop or server. In that case, it means you have already created a default user on your system, even on the cloud also Ubuntu is installed with preconfigured default user account.
You can do all administrative tasks using this user, but sometimes you need to create another user for your team member or something else.
Here, In this ttorial, I’ll show you how to create a new user on Ubuntu Desktop or Server system.
You should have root or superuser privileges to create a new user on Ubuntu Server or Desktop.
How to do it…
Follow these steps to create the new user account:
To add a new user in Ubuntu, enter following command in your shell:
$ sudo adduser bob
Enter your password to complete the command with
Now enter a password for the new user:
Confirm the password for the new user:
Enter the full name and other information about the new user; you can skip this part by using the Enter key.
Y to confirm that information is correct:
This should have added new user to the system. You can confirm this by viewing the file
Adds a new user. Adds a new default group with the same name as the user. Chooses UID (user ID) and GID (group ID) conforming to the Debian policy. Creates a home directory with skeletal configuration (template) from /etc/skel. Creates a password for the new user. Runs the user script, if any.
If you want to skip the password prompt and finger information while adding the new user, use the following command:
$ sudo adduser --disabled-password --gecos "" username
Alternatively, you can use the useradd command as follows:
$ sudo useradd -s <SHELL> -m -d <HomeDir> -g <Group> UserName
-s specifies default login shell for the user -d sets the home directory for the user -m creates a home directory if one does not already exist -g specifies the default group name for the user
Creating a user with the command
useradd does not set password for the user account. You can set or change the user password with the following command:
$ sudo passwd bob
This will change the password for the user account
Note that if you skip the username part from the above command you will end up changing the password of the root account.
adduser, you can do five different tasks:
- Add a normal user
- Add a system user with system option
- Add user group with the
--groupoption and without the
- Add a system group when called with the
- Add an existing user to existing group when called with two non-option arguments
man adduserto get more details. You can also configure various default settings for the
addusercommand. A configuration file
/etc/adduser.confcan be used to set the default values to be used by the
delusercommands. A key value pair of configuration can set various default values, including the
homedirectory location, directory structure
skelto be used, default groups for new users, and so on. Check the manual page for more details on
adduser.confwith following command:
$ man adduser.conf
Creating user accounts in batch mode
In this section, you will see how to create multiple user accounts in batch mode without using any external tool.
You will need a user account with root or root privileges.
How to do it…
Follow these steps to create a user account in batch mode:
Create a new text file
users.txt with the following command:
$ touch users.txt
Change file permissions with the following command:
$ chmod 600 users.txt
users.txt with and add user account details:
$ nano users.txt
Press Ctrl + O to save the changes.
Press Ctrl + X to exit GNU nano.
$ sudo newusers users.txt to import all users listed in
/etc/passwd to confirm that users are created:
How it works…
We created a database of user details listed in same format as the passwd file. The default format for each row is as follows:
username: This is the login name of the user. If a user exists, information for user will be changed; otherwise, a new user will be created. password: This is the password of the user. uid: This is the uid of the user. If empty, a new uid will be assigned to this user. gid: This is the gid for the default group of user. If empty, a new group will be created with the same name as the username. full name: This information will be copied to the gecos field. home_dir: This defines the home directory of the user. If empty, a new home directory will be created with ownership set to new or existing user. shell: This is the default login shell for the user.
users.txtfile accessible to owner only. This is to protect this file, as it contains the user’s login name and password in unencrypted format.