-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh-setcomment
executable file
·57 lines (48 loc) · 1.06 KB
/
ssh-setcomment
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
#!/bin/sh
set -e
set -u
fn_usage() { (
echo ""
echo "USAGE"
echo " ssh-setpass [ssh-key-file]"
echo ""
echo "EXAMPLE"
echo " ssh-setpass ~/.ssh/id_ed25519"
echo " OR"
echo " ssh-keygen -c ~/.ssh/id_ed25519"
echo ""
); }
fn_grep_keyfiles() { (
grep -r -- '-----BEGIN' ~/.ssh 2> /dev/null |
cut -d: -f1 |
sort -u ||
true |
while read -r my_keyfile; do
echo " ${my_keyfile}"
done
); }
main() {
my_key="${1:-"${HOME}/.ssh/id_rsa"}"
if test "{my_key}" = "help" ||
test "{my_key}" = "--help"; then
fn_usage
return 0
fi
if ! test -e "${my_key}"; then
{
echo ""
echo "ERROR"
echo " '${my_key}' not found"
echo ""
echo "KEYS FOUND"
if ! fn_grep_keyfiles; then
echo " (none)"
fi
} >&2
return 1
fi
echo ""
echo "${my_key}":
ssh-keygen -c -f "${my_key}"
}
main "${1-}"