2021-03-23 20:55:02 +00:00
|
|
|
#!/bin/sh
|
2021-10-11 08:02:14 +00:00
|
|
|
# Generate a key if it does not exist
|
|
|
|
# Print and copy its public part
|
|
|
|
# ARGS
|
|
|
|
# - key filename
|
|
|
|
# - encryption method (default ed25519)
|
|
|
|
# - further args for ssh-keygen
|
2021-03-23 20:55:02 +00:00
|
|
|
keys="$HOME/.ssh/keys"
|
2021-09-21 15:45:29 +00:00
|
|
|
name="${1:-id_ed25519}"
|
2021-03-23 20:55:02 +00:00
|
|
|
mkdir -p "$keys"
|
2021-09-21 15:45:29 +00:00
|
|
|
test -f "$keys/$name.pub" || ssh-keygen -t ${2:-ed25519} -b 4096 -f "$keys/$name" -q -N ""
|
2021-03-23 20:55:02 +00:00
|
|
|
cat "$keys/$name.pub"
|
|
|
|
if test "$OSTYPE" = "cygwin"
|
|
|
|
then cat "$keys/$name.pub">/dev/clipboard
|
|
|
|
else xclip -sel clip 2>/dev/null <"$keys/$name.pub"
|
2022-01-30 11:33:09 +00:00
|
|
|
fi && echo "SSH Public key copied to clipboard" || true
|