GNU/Linux >> Linux Esercitazione >  >> Ubuntu

Come aggiungere utenti a Ubuntu?

Gli attuali sistemi operativi si distinguono per essere multiutente. Cioè, possono creare molti utenti con profili di utilizzo diversi. Ciò consente allo stesso sistema di essere utilizzato da persone diverse. Ma è anche possibile creare utenti di sistema specifici per determinati servizi o applicazioni di rete. In ogni caso, grazie a questo post imparerai come aggiungere utenti a Ubuntu.

In questo tutorial useremo il terminale, quindi puoi usarlo se hai un server o se utilizzi il sistema con un'interfaccia grafica.

Il comando Linux useradd

In Ubuntu, il comando per creare un nuovo utente è useradd . Questo comando è abbastanza facile da usare ma ha alcune opzioni che ti permettono di personalizzare la creazione.

Apri un terminale ed esegui questo comando per ottenere informazioni su useradd:

useradd --help

E otterrai un output dello schermo come quello qui sotto:

Usage: useradd [options] LOGIN
       useradd -D
       useradd -D [options]

Options:
  -b, --base-dir BASE_DIR       base directory for the home directory of the
                                new account
  -c, --comment COMMENT         GECOS field of the new account
  -d, --home-dir HOME_DIR       home directory of the new account
  -D, --defaults                print or change default useradd configuration
  -e, --expiredate EXPIRE_DATE  expiration date of the new account
  -f, --inactive INACTIVE       password inactivity period of the new account
  -g, --gid GROUP               name or ID of the primary group of the new
                                account
  -G, --groups GROUPS           list of supplementary groups of the new
                                account
  -h, --help                    display this help message and exit
  -k, --skel SKEL_DIR           use this alternative skeleton directory
  -K, --key KEY=VALUE           override /etc/login.defs defaults
  -l, --no-log-init             do not add the user to the lastlog and
                                faillog databases
  -m, --create-home             create the user's home directory
  -M, --no-create-home          do not create the user's home directory
  -N, --no-user-group           do not create a group with the same name as
                                the user
  -o, --non-unique              allow to create users with duplicate
                                (non-unique) UID
  -p, --password PASSWORD       encrypted password of the new account
  -r, --system                  create a system account
  -R, --root CHROOT_DIR         directory to chroot into
  -s, --shell SHELL             login shell of the new account
  -u, --uid UID                 user ID of the new account
  -U, --user-group              create a group with the same name as the user
  -Z, --selinux-user SEUSER     use a specific SEUSER for the SELinux user mapping
      --extrausers              Use the extra users database

Da esso possiamo ricavare la sintassi di base del comando:

useradd [options] [username]

Questo comando deve essere eseguito come utente root. O almeno in aggiunta al comando sudo.

Esamineremo ora le opzioni più comuni per questo comando.

Aggiunta di utenti in Ubuntu con useradd

Per aggiungere un utente in Ubuntu, basta eseguire il seguente comando:

sudo useradd [username]

Se vuoi creare un nuovo utente chiamato atechtown , sarebbe il seguente:

sudo useradd atechtown

Tuttavia, saremo in grado di utilizzare le opzioni per migliorare la creazione.

Come sai l'utente che il sistema crea di default, ha assegnato una cartella home, per assegnarne una devi aggiungere l'opzione -m

sudo useradd -m atechtown

Questo creerà il nuovo utente e assegnerà il /home/atechtown directory come home

Inoltre, puoi impostare direttamente quello che vuoi che sia l'indirizzo di casa. In questo caso, l'opzione da utilizzare è -d

sudo useradd -d [directory] atechtown

Ad esempio:

sudo useradd -d /opt/atechtown atechtown

A volte è conveniente creare un utente e non la sua cartella personale. Questo è utile se creiamo un utente dedicato ad alcuni servizi del sistema. Per questo, il -M l'opzione è quella giusta.

sudo useradd -M atechtown

Un'altra cosa molto utile è creare il nuovo utente e una volta assegnato al gruppo principale di utenti e una volta aggiunto ai gruppi secondari come sudo.

In questo caso, per assegnarlo ad un gruppo primario utilizziamo l'opzione -g e per i gruppi secondari -G

Ad esempio:

useradd -g users -G sudo,adm atechtown

E se fosse il momento di creare un account che sappiamo essere temporaneo? Bene, il comando useradd ha l'opzione -e che definisce una data in cui l'account scadrà.

Ad esempio:

sudo useradd -e 2020-12-30 atechtown

Ciò indica che l'account scadrà il 30 dicembre 2020. Favoloso, vero?

Se hai diverse shell nel sistema come zsh puoi specificare quale utilizzerà il nuovo utente. Questo è ciò che il -s l'opzione è per.

sudo useradd -s /usr/bin/zsh atechtown

Ricorda che tutte le opzioni che ti ho insegnato possono essere combinate in un unico comando.

Ora che l'utente è stato creato, devi assegnargli una password. Puoi farlo con il passwd comando.

sudo passwd [username]

Nel nostro caso:

sudo passwd atechtown

Lì dovrai definire una password e confermarla. Ora sai come aggiungere e creare utenti in Ubuntu.

Conclusione

L'aggiunta di utenti a un sistema come Ubuntu può essere un'attività di base, ma è sempre utile sui computer acquistati. Tuttavia, questo non si applica solo quando Ubuntu viene utilizzato su un sistema desktop, ma anche a livello di server.

Per ulteriori informazioni sul comando useradd, puoi controllare questo link.

Inoltre, ti invitiamo a leggere il nostro post sul comando rsync.


Ubuntu
  1. Come aggiungere utenti a un gruppo in Linux

  2. Come aggiungere un utente a un gruppo in Linux

  3. Come aggiungere utenti a sudoer e aggiungere utenti a gruppi sudo su Ubuntu

  4. Aggiungi e rimuovi utenti su Ubuntu 20.04 - Come eseguire questa attività?

  5. Come aggiungere utenti al contenitore Docker?

Come aggiungere utenti a Sudoers (e rimuovere) su Ubuntu

Come aggiungere, eliminare e concedere privilegi Sudo agli utenti in Ubuntu

Come aggiungere e rimuovere utenti in Debian

Come aggiungere utenti a Sudoer su Ubuntu 20.04

Come aggiungere utenti a Sudoer su Ubuntu 22.04

Come creare/aggiungere utenti in Linux