[CENTOS] [Linux] User / group command summary

User and group operations are not done frequently and will be forgotten, so I will summarize them.

User-related commands

Check user list

cat /etc/passwd
###Execution result############
user_name1:1001:1001::/home/user_name1:/bin/bash
user_name2:x:1002:1002::/home/user_name2:/bin/bash

User created

useradd {user_name}

User deletion

userdel {user_name}

Group related commands

Group list confirmation

cat /etc/group
###Execution result############
root:x:0:
~ ~ Omitted ~ ~
group_name1:x:1003:user_name1,user_name2
group_name2:x:1004:user_name1

Group creation

groupadd {group_name}

Group deletion

groupdel {group_name}

Confirmation of users belonging to the group

getent group {group_name}
###Execution result############
group_name1:x:1003:user_name1,user_name2

Check the group to which the user belongs

groups {user_name}
#Execution result
user_name1 : user_name1 group_name1 group_name2

If you also want to know the UID and GID

id {user_name}
###Execution result############
uid=1001(user_name1) gid=1001(user_name1) groups=1001(user_name1),1003(group_name1),1004(group_name2)

gid= ... Primary group groups = ... the first is the Primary group, the second is the Secondary group

Change primary group

usermod -g {group_name} {user_name}

Other (secondary or later) affiliation group change / multiple addition

※※Caution※※ The -G option ** ignores and overwrites existing groups **. If you want to add a group while keeping the existing group, you need to ** specify the existing group as well **. You can check the existing group with ʻid {user_name} `.

usermod -G {group_name} {user_name}

To specify more than one, separate them with , (comma).

usermod -G {group_name1},{group_name2} {user_name}

Delete other (secondary or later) affiliated groups

Take advantage of the property of ** ignoring and overwriting ** existing groups of the -G option. Check the existing group with ʻid {user_name} `, and specify the group you want to delete.

usermod -G {group_name1},{group_name2} {user_name}

Recommended Posts

[Linux] User / group command summary
Linux Command Summary
[Linux] Basic command summary
Linux command # 4
Linux command # 3
Linux Summary
Linux command # 5
Linux command list
linux at command
[Linux] Search command
Linux command <Basic 2>
[Linux command summary] Command list [Must-see for beginners]
Linux user commands
Linux server command
Linux # Command Memo 1
Linux command [read]
[Basic] linux command
Linux [shell command]
[Linux] Command / Knowledge
My linux command
Linux command <Basic 1>
Linux command collection
Linux mkdir command
Linux command basics
[Linux] Git command
Docker command summary
Linux (command memory)
[Linux] Volume configuration command
Linux command cheat sheet
Linux command (sequential update)
Linux basic command memorandum
[Linux] Group related commands
Linux command [File operation]
OpenVPN Summary + Amazon Linux2
Linux command for self-collection
linux command error collection 1
[Infrastructure] While command summary
Image related command summary
[Linux] Change user password
Linux user addition, how to use the useradd command
linux sar command CPU usage
[Linux] tar.gz compression / decompression command
What is Linux? [Command list]
Linux a summary shortcut key
Add Linux user, how to use useradd command (password specification)
Summary of Linux distribution types
Linux FD event API summary
Easy df command on Linux
[Linux] [Initial Settings] [Flutter] Summary
Linux tar xz command memo
linux: create original Terminal command
[Note] Useful linux command collection
A brief summary of Linux
Linux command memorandum [for beginners]
Linux PC spec check command
[Linux] [C / C ++] backtrace acquisition method summary
[Infrastructure] Linux command, shell script collection
[Linux convenient command] Try inserting exa
Command to create Linux Live USB
Jupyter Notebook Magic Command Personal Summary
[Linux] OS recovery with restore command