24/7/365 Support

Creating Ubuntu user account

While installing Ubuntu, we add a primary user account on the server; if you are using the cloud image, it comes preinstalled with the default user. This single user is enough to get all tasks done in Ubuntu. There are times when you need to create more restrictive user accounts. This recipe shows how to add a new user to the Ubuntu server.

Getting ready

You will need super user or root privileges to add a new user to the Ubuntu server.

How to do it…

Follow these steps to create the new user account:

  1. To add a new user in Ubuntu, enter following command in your shell:
    $ sudo adduser bob
  2. Enter your password to complete the command with sudo privileges:
  3. Now enter a password for the new user:
  4. Confirm the password for the new user:
  5. Enter the full name and other information about the new user; you can skip this part by pressing the Enter key.
  6. Enter Y to confirm that information is correct:.

This should have added new user to the system. You can confirm this by viewing the file /etc/passwd:

How it works…

In Linux systems, the adduser command is higher level command to quickly add a new user to the system. Since adduser requires root privileges, we need to use sudo along with the command, adduser completes following operations:

  1. Adds a new user.
  2. Adds a new default group with the same name as the user.
  3. Chooses UID (user ID) and GID (group ID) conforming to the Debian policy.
  4. Creates a home directory with skeletal configuration (template) from /etc/skel.
  5. Creates a password for the new user.
  6. 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

Where:

  • -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 bob.

Note that if you skip the username part from the above 

command you will end up changing the password of the root account.

There's more…

With adduser, you can do five different tasks:

  • Add a normal user
  • Add a system user with system option
  • Add user group with the--group option and without the--system option
  • Add a system group when called with the --system option
  • Add an existing user to existing group when called with two non-option arguments

Check out the manual page man adduser to get more details.

You can also configure various default settings for the adduser command. A configuration file /etc/adduser.conf can be used to set the default values to be used by the adduser, addgroup, and deluser commands. A key value pair of configuration can set various default values, including the home directory location, directory structure skel to be used, default groups for new users, and so on. Check the manual page for more details on adduser.conf with following command:

$ man adduser.conf

See also

Help Category:

What Our Clients Say