What commands can I use to create and manage users and groups from the command shell of an Amazon Elastic Compute Cloud (Amazon EC2) Ubuntu Linux instance?

The following commands are used to create and manage users from the command shell of an EC2 Ubuntu Linux instance. For more information about these commands, including optional switches and configuration values, see Ubuntu Manuals - 18.04 LTS.

adduser

adduser adds users based on command-line options and configuration variables in the /etc/adduser.conf file. The adduser command must be preceded by the sudo qualifier to temporarily grant the necessary privileges. Typically user names are lower-case letters. You can use a dash (-) or an underscore (_) in a user name. If you use Samba, user names can end in a dollar sign ($).

For example, the following command creates the new user account bob.

sudo adduser bob

Add the command-line switch --ingroup GROUP to add the new user to a different group.

The following command creates the new user account bob and adds them to the betausers user group:

sudo adduser bob --ingroup betausers

For a comprehensive list of adduser configuration variables, see adduser.conf.

addgroup

addgroup adds groups based on command-line options and configuration variables in the /etc/adduser.conf. The addgroup command must be preceded by the sudo qualifier to temporarily grant the necessary privileges. Typically group names are lower-case letters. You can use a dash (-) or an underscore (_) in a group name

For example, the following command creates the new group betausers.

sudo addgroup betausers

For a comprehensive list of configuration variables, see adduser.conf.

deluser

deluser removes users from the system or from the specified group based on command-line options and configuration variables in the /etc/deluser.conf file. The deluser command also can delete a group itself. The deluser command must be preceded by the sudo qualifier to temporarily grant the necessary privileges.

The following command deletes the user account bob.

sudo deluser bob

Add the command-line switch --group groupname to delete user from a specific group (but leaves the user in the system).

The following command removes the user bob from the betausers group.

sudo deluser bob --group betausers

The following command removes the group betausers from the system.

sudo deluser --group betausers

For a comprehensive list of configuration variables, see deluser.conf.

delgroup

delgroup removes groups based on command-line options and configuration variables in the /etc/deluser.conf file. The delgroup command must be preceded by the sudo qualifier to temporarily grant the necessary privileges.

For example, the following command deletes the group betausers.

sudo delgroup betausers

For a comprehensive list of configuration variables, see deluser.conf.

Additional commands for managing users and groups

  • chage - Change the expiration time for a user's password.
  • chfn - Change a user name and/or associated user information.
  • chsh - Change the shell for a user.
  • chgrp - Change group ownership of a file.
  • chown - Change user and group ownership of a file.
  • gpasswd - Administer /etc/group and /etc/gshadow.
  • groupadd - Create a new group.
  • groupdel - Delete a group.
  • groupmod - Modify a group definition.
  • groups - Display all the groups a user belongs to.
  • grpck - Verify the integrity of group files.
  • id - Display all group or user ID numbers for a specified user.
  • newgrp - Assign new group identifications for a user.
  • newusers - Batch utility to update and create new users.
  • nologin - Disable login functionality for unprivileged users.
  • passwd - Change a user's password.
  • su - Become another user during a login session.
  • useradd - Create a new user or change default new user information.
  • userdel - Delete a user account and related files.
  • usermod - Modify a user account.

List all regular users:

awk -F':' '{ print $1}' /etc/passwd

List all groups:  

cut -d: -f1  /etc/group

Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center.

Published: 2015-02-16

Updated: 2018-05-21