Improve SSH key setup and validation in deploy.yml #17
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
rdenadai/web.redecapivara.social!17
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "rdenadai-patch-7"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Updated SSH key setup to use printf for formatting and added validation for the SSH key.
Pull Request Overview
This PR improves the SSH key handling in the deployment workflow by switching to printf for writing the private key and adding a validation step for the SSH key.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@ -36,9 +36,12 @@ jobs:- name: Set up SSH keyrun: |mkdir -p ~/.sshAfter creating ~/.ssh, set directory permissions to 700 to satisfy SSH's security expectations and avoid it ignoring keys due to permissive directory permissions.
@ -39,2 +39,3 @@echo "${{ secrets.VM_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa# Use printf instead of echo to preserve formattingprintf '%s\n' "${{ secrets.VM_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsachmod 600 ~/.ssh/id_rsa[nitpick] Using printf '%s\n' appends an extra newline which can alter the secret's exact content; prefer printf '%s' to write the key verbatim.
@ -42,1 +42,4 @@# Verify key is validssh-keygen -l -f ~/.ssh/id_rsa || { echo "Invalid SSH key"; exit 1; }ssh-keyscan -p ${{ secrets.SSH_PORT }} -H "${{ secrets.VM_IP }}" >> ~/.ssh/known_hosts 2>/dev/null || truessh-keygen -l expects a public key; running it on a private key commonly returns 'invalid format' even when the key is valid. To actually validate the private key, use ssh-keygen -y (which reads a private key and outputs the public key) and check its exit status.
@ -42,2 +43,4 @@ssh-keygen -l -f ~/.ssh/id_rsa || { echo "Invalid SSH key"; exit 1; }ssh-keyscan -p ${{ secrets.SSH_PORT }} -H "${{ secrets.VM_IP }}" >> ~/.ssh/known_hosts 2>/dev/null || true- name: Test SSH connection[nitpick] Redirecting stderr to /dev/null and forcing success with || true hides host key retrieval failures, making issues hard to debug and potentially leaving known_hosts empty. Consider failing fast on ssh-keyscan errors or at least logging them so that a missing host key doesn't go unnoticed.