Help us understand the problem. What is going on with this article?

【自分用】新規ユーザを作成して、鍵ファイルを作成するshell

More than 5 years have passed since last update.

概要

ユーザと鍵を毎度毎度コマンドうつの面倒だからshellにしてみた。
自分用スクリプト第二弾。
rootで実行。対話的に動く。

以下script

useradd.sh
#!/bin/sh -x
clear

# input user information
echo "input User Name"
read UserName
echo
echo "input UID"
read UserID
echo
echo "input GroupName"
read GroupName
echo
echo "input GID"
read GroupID
echo
echo "input Password"
read PASSWD
echo

# confirm input data
echo "UserName:  ${UserName}"
echo "UID:       ${UserID}"
echo "GroupName: ${GroupName}"
echo "GroupID:   ${GroupID}"
echo "Password:  ${PASSWD}"
echo

echo "Are You OK?"
read RES
case ${RES} in
   Yes|yes|Y|y )
      break ;;
   No|no|N|n )
      exit ;;
   * )
      echo
      echo
      echo "input Yes or No"
      exit ;;
esac

# user/group create
echo
groupadd -g ${GroupID} ${GroupName}
useradd -g ${GroupID} -u ${UserID} ${UserName}
echo ${PASSWD} | passwd --stdin ${UserName}

# ssh key create
mkdir /home/${UserName}/.ssh
ssh-keygen -f /home/${UserName}/.ssh/rsa -t rsa -N ""

# ssh key change status
mv /home/${UserName}/.ssh/rsa /home/${UserName}/.ssh/${UserName}.pem
mv /home/${UserName}/.ssh/rsa.pub /home/${UserName}/.ssh/authorized_keys
chmod 700 /home/${UserName}/.ssh
chmod 600 /home/${UserName}/.ssh/*
chown -R ${UserName}. /home/${UserName}/.ssh
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした