X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=ssh-utils%2Fssh-pubkey.sh;h=588dcca307f8e859683e1e5f45d6fd8748078ef3;hb=59074b5d9d0a9f03a0f525011a3cbd37428347c4;hp=044e1e11667b243cad6bd9f71581346028cd2e4f;hpb=bd7e09df58fe2012813f60d299c33690aaab4eea;p=webi-installers%2F.git diff --git a/ssh-utils/ssh-pubkey.sh b/ssh-utils/ssh-pubkey.sh index 044e1e1..588dcca 100644 --- a/ssh-utils/ssh-pubkey.sh +++ b/ssh-utils/ssh-pubkey.sh @@ -1,25 +1,41 @@ #!/bin/bash -set -e -set -u +{ + set -e + set -u -mkdir -p "$HOME/.ssh/" + if [ ! -d "$HOME/.ssh" ]; then + mkdir -p "$HOME/.ssh/" + chmod 0700 "$HOME/.ssh/" + fi -if [ ! -f "$HOME/.ssh/id_rsa" ]; then - ssh-keygen -b 2048 -t rsa -f "$HOME/.ssh/id_rsa" -q -N "" - echo "" -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/id_rsa.pub" ]; then - ssh-keygen -y -f "$HOME/.ssh/id_rsa" > "$HOME/.ssh/id_rsa.pub" - echo "" -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 "" + fi + + if [ ! -f "$HOME/.ssh/id_rsa.pub" ]; then + ssh-keygen -y -f "$HOME/.ssh/id_rsa" > "$HOME/.ssh/id_rsa.pub" + echo "" + fi -# TODO use the comment (if any) for the name of the file -echo "" -echo "~/Downloads/id_rsa.$(whoami).pub": -echo "" -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 "" + # TODO use the comment (if any) for the name of the file + echo "" + echo "~/Downloads/id_rsa.$(whoami).pub": + echo "" + 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 "" +}