GNU/Linux >> Belajar Linux >  >> Ubuntu

Pembuatan Pengguna Dengan Opsi Perintah Mutiple?

Apakah mungkin untuk membuat pengguna dengan direktori home default tertentu dan menambahkan pengguna ke grup utama tertentu dengan satu perintah?

Jawaban yang Diterima:

Anda dapat melakukannya dengan useradd . Saya menambahkan baris untuk membuktikan bahwa itu mungkin. Secara umum menjalankan passwd setelah itu ketika melakukannya secara manual lebih aman dan cara terbaik untuk pergi.

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

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

Jadi sebaiknya Anda melakukannya dalam dua langkah, dengan cara ini kata sandi tidak masuk ke sistem.

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

Dan Anda bahkan bisa memasukkan ini ke dalam satu tindakan:

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

Ubuntu
  1. Perintah DD Linux - 15 Contoh dengan Semua Opsi

  2. Samba Mount Dengan Password Prompt Sebagai Pengguna Non-root?

  3. Opsi Su – Menjalankan Perintah Sebagai Pengguna Lain?

  1. Cara Menggunakan Perintah su di Linux dengan Contoh

  2. Tambahkan Pengguna ke Grup di Linux, Bagaimana Melakukannya (Dengan Contoh)

  3. Menambahkan pengguna yang ada ke grup dengan boneka

  1. Cara Mengubah Pemilik File/Grup dengan Perintah chown di Linux

  2. Perintah Chown di Linux (Kepemilikan File)

  3. Perintah Chgrp Linux dengan Contoh