GNU/Linux >> Linux Esercitazione >  >> Ubuntu

Creazione di utenti con più opzioni di comando?

È possibile creare un utente con una directory home predefinita specifica e aggiungere l'utente a un gruppo primario specifico con un singolo comando?

Risposta accettata:

Puoi farlo con useradd . Ho aggiunto la riga per dimostrare che è possibile. In generale eseguendo passwd in seguito, quando farlo manualmente è più sicuro e il modo migliore per procedere.

sudo useradd -U -m -G <group> -p <password> <user-name>

Da man useradd :

   -G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
       A list of supplementary groups which the user is also a member of.
       Each group is separated from the next by a comma, with no
       intervening whitespace. The groups are subject to the same
       restrictions as the group given with the -g option. The default is
       for the user to belong only to the initial group.

   -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.

   -U, --user-group
       Create a group with the same name as the user, and add the user to
       this group.

       The default behavior (if the -g, -N, and -U options are not
       specified) is defined by the USERGROUPS_ENAB variable in
       /etc/login.defs.

   -p, --password PASSWORD
       The encrypted password, as returned by crypt(3). The default is to
       disable the password.

       Note: This option is not recommended because the password (or
       encrypted password) will be visible by users listing the processes.

       You should make sure the password respects the system's password
       policy.

Quindi dovresti farlo meglio in due passaggi, in questo modo la password non viene registrata dal sistema.

sudo useradd -U -m -G <group> <user-name>
sudo passwd <user-name>

E puoi ottenere anche questo in un'azione di una riga:

sudo useradd -U -m -G <group> <user-name> && sudo passwd <user-name>

Ubuntu
  1. Comando Linux DD - 15 esempi con tutte le opzioni

  2. Aggiungi utente al gruppo in Linux, come farlo (con esempi)

  3. Samba Mount con richiesta di password come utente non root?

  4. Opzioni Su - Esecuzione del comando come un altro utente?

  5. Aggiunta di un utente esistente a un gruppo con pupazzo

su Comando in Linux

Modifica gli account utente con il comando Usermod

Elimina gli utenti in Linux con il comando Userdel

Modifica i gruppi in Linux con il comando groupmod

Elimina i gruppi in Linux con il comando groupdel

Comando Linux passwd – Modifica password utente