-
Notifications
You must be signed in to change notification settings - Fork 3
/
keygen
executable file
·47 lines (40 loc) · 1.49 KB
/
keygen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env sh
# キーペアの生成スクリプト (UTF-8)
# ======================================
#
# Githubが対応するRSAキーペアを作成します。キー長は4096bitです。
#
# - 使い方の例:
# 以下のコマンドでキーペアを作成します。
# $ ./keygen.sh [email protected] githubkeypair
# この場合、~/.ssh/ディレクトリに秘密鍵githubkeypairと公開鍵githubkeypair.pubが生成されます。
#
# - 注意:利用前にスクリプトに実行権限を与えるのを忘れないでください。
#
# -----------------------------------------------------------------------------
# Requirement check
# -----------------------------------------------------------------------------
if ! type ssh-keygen 2>/dev/null 1>/dev/null; then
echo >&2 'ssh-keygen コマンド(openssh)がインストールされていません。'
exit 1
fi
# ヘルプ表示
# ----------
if [ $# -lt 2 ]; then
echo
echo "使い方: $0 <email> <keyname>"
echo
echo "- <email> : Githubで使用しているメールアドレス(公開鍵内に埋め込まれます)"
echo "- <keyname> : 希望するキーペアの名前(パス名ではない)"
echo
exit 1
fi
if [ ! -d ~/.ssh ]; then
mkdir ~/.ssh
chmod 700 ~/.ssh
fi
ssh-keygen -t rsa -b 4096 -N "" -m PEM -C "$1" -f ~/.ssh/"$2"
echo
echo "This is the generated pubkey. Register it on your github account. Then try the 'check' command for error check."
echo
cat ~/.ssh/"${2}.pub"