Outils du site

Ne dites pas: \"J'ai trouvé la vérité\", mais plutôt: \"J'ai trouvé une vérité\". Ne dites pas: \"J'ai trouvé le chemin de l'âme\". Dites plutôt: \"J'ai rencontré l'âme marchant sur mon chemin\". Car l'âme marche sur tous les chemins.L'âme ne marche pas sur une ligne de crête, pas plus qu'elle ne croit tel un roseau.L'âme se déploie, comme un lotus aux pétales innombrables. [Khalil GIBRAN]

04-linux:10-administration:88-users

Users

Utilisateurs

  • Liste des utilisateurs :

cat /etc/passwd

  • Liste des sudoers :

/etc/sudoers

  • Ajout d'un utilisateur :

sudo useradd -m -g initial_group -G additional_groups -s login_shell username

-m, --create-home

Create the user's home directory if it does not exist. The files and directories contained in the skeleton directory (which can be defined with the -k option) will be copied to the home directory.

By default, if this option is not specified and CREATE_HOME is not enabled, no home directories are created.

  • Suppression d'un utilisateur :

sudo userdel -r username

The -r option specifies that the user's home directory and mail spool should also be deleted.
  • Modification des UIDs et GIDs
usermod -u <NEWUID> <LOGIN>    
groupmod -g <NEWGID> <GROUP>
find / -user <OLDUID> -exec chown -h <NEWUID> {} \;
find / -group <OLDGID> -exec chgrp -h <NEWGID> {} \;
usermod -g <NEWGID> <LOGIN>

Groupes

Chaque utilisateur est membre d'un ou plusieurs groupes.

  • Liste des groupes :

cat /etc/group

  • Membres d'un groupe :

getent group groupname

  • Création d'un groupe :

sudo groupadd group

  • Modification d'un nom de groupe :

sudo groupmod -n new_group old_group

  • Suppression d'un groupe :

sudo groupdel group

  • Groupes d'un utilisateur :

groups username

En plus détaillé :

id username

  • Changement du groupe primaire d'un utilisateur

sudo usermod -g <primary_group> <user>

  • Ajout d'un utilisateur à un groupe (groupe secondaire de l'utilisateur)

sudo usermod -a -G <additional_groups> <user>

If the -a option is omitted in the usermod command above, the user is removed from all groups not listed in additional_groups (i.e. the user will be member only of those groups listed in additional_groups).

-G : Each group is separated from the next by a comma, with no intervening whitespace.

  • Suppression d'un utilisateur d'un groupe :

sudo gpasswd -d user group

Partage dossier entre utilisateurs

sudo mkdir /home/public

sudo /usr/sbin/groupadd share

sudo chown -R root.share /home/public

sudo /usr/bin/gpasswd -a user1 share

sudo chmod ug+rwx -R /home/public

# set the SGID bit on the shared directory. Normally whenever you create files in a directory, by default it belongs to the default group or user. When a file is created in a directory with the SGID bit set it belongs to the same group as the directory. The result being that all users of the “share” group can create/alter files in “/home/public” directory.

sudo chmod g+s /home/public

Sudoers

remove user from sudoers group sudo deluser <username> sudo

Dernière modification : 2023/03/05 02:15