-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_ssh_keys
More file actions
executable file
·97 lines (83 loc) · 1.67 KB
/
generate_ssh_keys
File metadata and controls
executable file
·97 lines (83 loc) · 1.67 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
#
# Generate an SSH key pair.
#
# Dependencies: coreutils, openssh, util-linux
set -o nounset -o pipefail
readonly L_OPTS="comment:,help,version"
readonly OPTS="C:c:hVv"
readonly CMD="${0##*/}"
readonly USAGE="${CMD} [OPTION]... FILE"
readonly USAGE_ERR_MSG=$(
cat <<END
Usage: ${USAGE}
Try '${CMD} --help' for more information.
END
)
readonly VERSION_INFO=$(
cat <<END
${CMD} (scripts) 1.0.0
This is free and unencumbered software released into the public domain.
For more information, please refer to <https://unlicense.org/>.
END
)
readonly HELP=$(
cat <<END
SYNOPSIS
${USAGE}
DESCRIPTION
Generate an SSH key pair {FILE, FILE.pub} using the ed25519 key type.
OPTIONS
-C, -c, --comment COMMENT, --comment=COMMENT
add a comment to the keys (no comment by default)
-h, --help
display this help and exit
-V, -v, --version
display version and exit
END
)
opts=$(getopt --options=${OPTS} --longoptions=${L_OPTS} --name "${CMD}" -- "$@")
if (($? != 0)); then
echo "${USAGE_ERR_MSG}"
exit 2
fi
eval set -- "${opts}"
comment=""
need_help=false
need_version=false
while true; do
case "$1" in
-C | -c | --comment)
comment="$2"
shift 2
;;
-h | --help)
need_help=true
shift
break
;;
-V | -v | --version)
need_version=true
shift
break
;;
--)
shift
break
;;
esac
done
if [[ $need_help == true ]]; then
echo "${HELP}"
exit 0
fi
if [[ $need_version == true ]]; then
echo "${VERSION_INFO}"
exit 0
fi
if (($# != 1)); then
echo "${CMD}: expected 1 argument; got $#"
echo "${USAGE_ERR_MSG}"
exit 2
fi
ssh-keygen -a 128 -C "${comment}" -f "$1" -t "ed25519"