LoginSignup
0
0

More than 1 year has passed since last update.

ユーザ作成の自動化

Last updated at Posted at 2021-11-29

ユーザ作成の自動化
※ユーザー名と同じ名前でパスワードを作成します。
※初回ログイン時にパスワード変更を求めます。

使い方

sh user_add.sh ユーザ名 グループ名
user_add.sh
#!/bin/sh

if [ $# -ne 2 ]
then
   #標準出力を標準エラー出力に変更。まぁ好み次第で不要でもOK。
   echo "パラメータがユーザ名とグループ名でない" >&2
   exit 100
fi

USER_PASS=$1
GROUP_INFO=$2

grep ${GROUP_INFO} /etc/group

if [ $? -ne 0 ]
then
  groupadd ${GROUP_INFO}

fi

useradd ${USER_PASS} -g ${GROUP_INFO}

echo ${USER_PASS} | passwd --stdin ${USER_PASS}

passwd -e ${USER_PASS}


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0