GNU/Linux >> Linux の 問題 >  >> Ubuntu

複数のコマンドオプションを使用したユーザー作成?

特定のデフォルトのホームディレクトリを持つユーザーを作成し、1つのコマンドで特定のプライマリグループにユーザーを追加することは可能ですか?

承認された回答:

これはuseraddで行うことができます 。それが可能であることを証明するために行を追加しました。一般的にpasswdを実行します 後で手動で行う場合は、より安全で最善の方法です。

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

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.

したがって、2つのステップで実行することをお勧めします。これにより、パスワードがシステムによってログに記録されなくなります。

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

そして、これも1行のアクションにまとめることができます:

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

Ubuntu
  1. LinuxDDコマンド-すべてのオプションを使用した15の例

  2. Linuxのグループにユーザーを追加する方法(例を含む)

  3. 非rootユーザーとしてパスワードプロンプトでSambaマウントしますか?

  1. 例を使用してLinuxでsuコマンドを使用する方法

  2. Suオプション–別のユーザーとしてコマンドを実行しますか?

  3. puppet を使用して既存のユーザーをグループに追加する

  1. Linuxでchownコマンドを使用してファイル/グループ所有者を変更する方法

  2. LinuxでのChownコマンド(ファイル所有権)

  3. 例を含むLinuxChgrpコマンド