Last active
December 17, 2015 02:19
-
-
Save cs-sonar/5535319 to your computer and use it in GitHub Desktop.
一行の実行でLinuxユーザーを作るシェルスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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