maybe just use ssh-keygen
All checks were successful
test / test (push) Successful in 4s

This commit is contained in:
Lucy 2025-04-05 13:17:37 +02:00
parent 5fb7d17f0a
commit 9736f68157
3 changed files with 3 additions and 35 deletions

View file

@ -12,7 +12,7 @@ jobs:
image: 'code.forgejo.org/oci/ci:1'
steps:
- uses: actions/checkout@v4
- run: for i in *.pub; do ./check_key.sh $i; done
- run: for i in *.pub; do ssh-keygen -l -f $i; done
- run: |
echo assembeling authorized keys &&
cat *.pub > authorized_keys

View file

@ -1 +1,2 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDWcYvzMXydV3n3S5DfT5C0TGQROKC2OUr/WLo+ohqZ7ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICYfR9R1unNcDxCiS9lIYG1xEgZHF9/1zHrOn/Gn9tqB
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDWcYvzMXydV3n3S5DfT5C0TGQROKC2OUr/WLo+ohqZ7
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICYfR9R1unNcDxCiS9lIYG1xEgZHF9/1zHrOn/Gn9tqB

View file

@ -1,33 +0,0 @@
#!/bin/bash
# Input file containing the SSH public keys
key_file=$1
# Read the file line by line
while IFS= read -r line; do
# Skip empty lines
if [ -z "$line" ]; then
continue
fi
# Trim leading/trailing whitespace (preserving the key and comment structure)
trimmed_line=$(echo "$line" | xargs)
# Validate the SSH key format:
# Starts with ssh-<type>, followed by base64-encoded data, and an optional comment
echo $key_file
if ! echo "$trimmed_line" | grep -Eq '^ssh-(rsa|ed25519|dss|ecdsa) [A-Za-z0-9+/=]+ ?.*$'; then
echo "Invalid key format: $line"
exit 1
fi
# Ensure there is only one key on the line: a valid key should only have one space separating key data from the comment
space_count=$(echo "$trimmed_line" | grep -o ' ' | wc -l)
if [ "$space_count" -gt 2 ]; then
echo "Invalid: Multiple keys found on the same line"
exit 1
fi
done < "$key_file"
echo "All keys are valid and correctly formatted."