X-Git-Url: https://git.josue.xyz/?p=webi-installers%2F.git;a=blobdiff_plain;f=ssh-pubkey%2Fssh-pubkey.sh;fp=ssh-pubkey%2Fssh-pubkey.sh;h=f729276c67ee85bf5d9ab81b17ec3c980b5c9170;hp=c96a4a16dc2003207bbea25f4a8b6cdaa6c6320f;hb=91512157ab426c87e0a82b594620e90e324b23a3;hpb=b1d3b44f966332434d8ec49b2a0df569e9bf8c16 diff --git a/ssh-pubkey/ssh-pubkey.sh b/ssh-pubkey/ssh-pubkey.sh deleted file mode 120000 index c96a4a1..0000000 --- a/ssh-pubkey/ssh-pubkey.sh +++ /dev/null @@ -1 +0,0 @@ -../ssh-utils/ssh-pubkey.sh \ No newline at end of file diff --git a/ssh-pubkey/ssh-pubkey.sh b/ssh-pubkey/ssh-pubkey.sh new file mode 100644 index 0000000..f729276 --- /dev/null +++ b/ssh-pubkey/ssh-pubkey.sh @@ -0,0 +1,44 @@ +#!/bin/bash +set -e +set -u + +function main() { + + if [ ! -d "$HOME/.ssh" ]; then + mkdir -p "$HOME/.ssh/" + chmod 0700 "$HOME/.ssh/" + fi + + if [ ! -f "$HOME/.ssh/config" ]; then + # for the benefit of VSCode + touch "$HOME/.ssh/config" + chmod 0644 "$HOME/.ssh/config" + fi + + if [ ! -f "$HOME/.ssh/authorized_keys" ]; then + touch "$HOME/.ssh/authorized_keys" + chmod 0600 "$HOME/.ssh/authorized_keys" + fi + + if [ ! -f "$HOME/.ssh/id_rsa" ]; then + ssh-keygen -b 2048 -t rsa -f "$HOME/.ssh/id_rsa" -q -N "" + echo >&2 "" + fi + + if [ ! -f "$HOME/.ssh/id_rsa.pub" ]; then + ssh-keygen -y -f "$HOME/.ssh/id_rsa" > "$HOME/.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 -r "$HOME/.ssh/id_rsa.pub" "$HOME/Downloads/id_rsa.$(whoami).pub" + cat "$HOME/Downloads/id_rsa.$(whoami).pub" + echo >&2 "" +} + +main