Begin ssh script

This commit is contained in:
2021-04-11 17:21:20 +01:00
parent 5f533def6b
commit 67ad04d02c
4 changed files with 52 additions and 2 deletions

View File

@@ -0,0 +1,28 @@
#!/bin/bash
LABS=$(enpasscli -vault="$HOME/Documents/Enpass/Vaults/Primary" -sort show "Scarif: Labs" 2>&1)
LABSUN=$(echo "$LABS" | grep -Po "(?<=login: )\w+")
LABSPW=$(echo "$LABS" | grep -Po "(?<=pass : ).+(?=\")")
SSHPATH="$HOME/.ssh/id_ed25519"
ssh-keygen -t ed25519 -f "$SSHPATH" -N "" -q
generate_post_data() {
cat <<EOF
{
"key": "$(cat "$SSHPATH.pub")",
"read_only": false,
"title": "$USER@$(cat /etc/hostname)"
}
EOF
}
CREDENTIALS=$(echo "$LABSUN:$LABSPW" | base64)
curl --request POST \
-s \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
--data "$(generate_post_data)" \
--url "https://$CREDENTIALS@labs.scarif.space/api/v1/users/$LABSUN/keys"