Howto manage user and groups: Difference between revisions

From Vidalinux Wiki
Jump to navigation Jump to search
 
(8 intermediate revisions by the same user not shown)
Line 4: Line 4:
  UID 1-999 is used for system users
  UID 1-999 is used for system users
  UID 1000 and up are normal users
  UID 1000 and up are normal users
you can change this definitions on this file:
cat /etc/login.defs | grep GID
add user and create home folder:
add user and create home folder:
  useradd -m student
  useradd -m student
Line 22: Line 24:
add group:
add group:
  groupadd vidalinux
  groupadd vidalinux
to create a group with specific group id:
groupadd -g 1010 vidalinux
add user to group:
add user to group:
  gpasswd -a student vidalinux
  gpasswd -a student vidalinux
add user to more than one group:
add user to more than one group:
  usermod -G wheel,video,sound,lp student
  usermod -aG wheel,video,sound,lp student
to list all groups on our system:
list all groups and filter the result with grep:
  less /etc/group
  getent group | grep vidalinux
delete a group:
groupdel vidalinux
 
= usermod =
= usermod =
add a comment for a user:
usermod -c "course student user" student
to change the login shell of a user:
to change the login shell of a user:
  usermod -s /sbin/nologin username
  usermod -s /sbin/nologin username
change the home directory of a user:
usermod -d /opt/student student
change user login name:
usermod -l newuser currenuser
usermod -l student1 student
Locking a user account:
Locking a user account:
  usermod -L username
  usermod -L username
Unlock a user account:
Unlock a user account:
  usermod -U username
  usermod -U username
change the user id of a user
usermod -u 4000 student
Add user to group:
Add user to group:
  usermod -aG groupname username
  usermod -aG groupname username
Modify username to expire at specific date:
Modify username to expire at specific date:
  usermod -L -e 2019-10-05 user03
  usermod -L -e 2019-10-05 user03

Latest revision as of 18:41, 10 September 2021

creating users

UID definitions:

UID 0 is reserve for the root user only
UID 1-999 is used for system users
UID 1000 and up are normal users

you can change this definitions on this file:

cat /etc/login.defs | grep GID

add user and create home folder:

useradd -m student

specify user shell when creating the user:

useradd -m -s /bin/bash student

specify another location for user home folder:

useradd -m -d /opt/student student

specify default group name or group id:

useradd -m -g student 

specify userid:

useradd -m -u 1000 student

create user and add this user to different groups:

useradd -m -g student -G video,docker,sound,lp student

assign password to user:

passwd student

manage groups

add group:

groupadd vidalinux

to create a group with specific group id:

groupadd -g 1010 vidalinux

add user to group:

gpasswd -a student vidalinux

add user to more than one group:

usermod -aG wheel,video,sound,lp student

list all groups and filter the result with grep:

getent group | grep vidalinux

delete a group:

groupdel vidalinux

usermod

add a comment for a user:

usermod -c "course student user" student

to change the login shell of a user:

usermod -s /sbin/nologin username

change the home directory of a user:

usermod -d /opt/student student

change user login name:

usermod -l newuser currenuser
usermod -l student1 student

Locking a user account:

usermod -L username

Unlock a user account:

usermod -U username

change the user id of a user

usermod -u 4000 student

Add user to group:

usermod -aG groupname username

Modify username to expire at specific date:

usermod -L -e 2019-10-05 user03