Linux/User Management: Difference between revisions

From Dev Wiki
Jump to navigation Jump to search
(Add commands to update user passwords)
(Add user group commands)
Line 3: Line 3:
== Creating a New User ==
== Creating a New User ==
The most basic implementation is:
The most basic implementation is:
* <code>useradd <username></code>
* <code>useradd <user_name></code>


From there, you can add argument options such as:
From there, you can add argument options such as:
Line 21: Line 21:


Update password for another user account:
Update password for another user account:
* <code>passwd <username></code>
* <code>passwd <user_name></code>
 
 
== Group Management ==
 
=== Groups and Group Membership ===
View check all existing groups:
* <code>cat /etc/group</code>
 
View all members of a group:
* <code>getent group <group_name></code>
 
View all groups for given user:
* <code>groups <user_name></code>
 
 
=== Adding and Removing User Groups ===
Add current user to group:
* <code>groupadd <group_name></code>
 
Add given user to group:
* <code>usermod -a -G <group_name> <user_name></code>
 
Remove user from group:
* <code>gpasswd -d <user_name> <group_name></code>

Revision as of 02:28, 20 December 2019

Terminal commands to manage user accounts in linux.

Creating a New User

The most basic implementation is:

  • useradd <user_name>

From there, you can add argument options such as:

  • -M or --no-create-home - Skips creating a home directory for user.
  • -N or --no-user-group - Skips creating a group with the same name as user.
  • -G or --groups - Set additional user groups user is part of, during user creation.
  • -r or --system - Create a "system" account. Aka, a user with no password, no home directory, and is unable to log in.

Example:
useradd -G admins,webadmin,developers my_user
This creates a user called "my_user" that is associated with groups "admins", "webadmin", and "developers".


Updating User Password

Update password for current account:

  • passwd

Update password for another user account:

  • passwd <user_name>


Group Management

Groups and Group Membership

View check all existing groups:

  • cat /etc/group

View all members of a group:

  • getent group <group_name>

View all groups for given user:

  • groups <user_name>


Adding and Removing User Groups

Add current user to group:

  • groupadd <group_name>

Add given user to group:

  • usermod -a -G <group_name> <user_name>

Remove user from group:

  • gpasswd -d <user_name> <group_name>