Skip to content

Instantly share code, notes, and snippets.

@cs-sonar
Last active December 17, 2015 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cs-sonar/5535319 to your computer and use it in GitHub Desktop.
Save cs-sonar/5535319 to your computer and use it in GitHub Desktop.
一行の実行でLinuxユーザーを作るシェルスクリプト
#!/bin/sh
#
#[使い方]
#
#実行権限を与える
# chmod 755 ./useradd.sh
#
#第一引数にユーザー名、第二引数にパスワードを書いて実行
# ./useradd.sh username passwd
#
if [ $# -ne 2 ]; then
echo "error"
exit 1
fi
CHECKFLG=`cat /etc/passwd | grep "^$1:" | wc -l`
if [ $CHECKFLG -ne 0 ]; then
echo "duplicate error"
exit 1
fi
# make user
/usr/sbin/useradd $1 -m
# set user passwd
echo $1":"$2 | /usr/sbin/chpasswd
# chgroup
#作ったユーザーのグループを指定したいときはコメントアウトをはずす
#usermod -g users $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment