Files
vim-ale/ssh-pubkey/ssh-pubkey
2024-05-16 20:12:02 +00:00

45 lines
1021 B
Bash

#!/bin/sh
set -e
set -u
main() {
if ! test -d ~/.ssh; then
mkdir -p ~/.ssh/
chmod 0700 ~/.ssh/
fi
if ! test -f ~/.ssh/config; then
# for the benefit of VSCode
touch ~/.ssh/config
chmod 0644 ~/.ssh/config
fi
if ! test -f ~/.ssh/authorized_keys; then
touch ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
fi
if ! test -f ~/.ssh/id_rsa; then
ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N ""
echo >&2 ""
fi
if ! test -f ~/.ssh/id_rsa.pub; then
ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
echo >&2 ""
fi
# TODO use the comment (if any) for the name of the file
echo >&2 ""
#shellcheck disable=SC2088
echo >&2 "~/Downloads/id_rsa.$(whoami).pub":
echo >&2 ""
rm -f "$HOME/Downloads/id_rsa.$(whoami).pub"
cp -RPp "$HOME/.ssh/id_rsa.pub" "$HOME/Downloads/id_rsa.$(whoami).pub"
cat "$HOME/Downloads/id_rsa.$(whoami).pub"
echo >&2 ""
}
main