Loading...
Loading...
This skill should be used when the user asks to "rotate SSH keys", "regenerate SSH keys", "replace SSH keys", "renew SSH keys", or when the agent needs SSH access to a deployed VM for troubleshooting (logs, debugging, database access) but discovers the expected SSH key file is missing from the local disk (e.g. `~/.ssh/<repo-name>` does not exist). Also use when the user mentions "lost SSH key", "SSH key not found", "can't SSH into server", "permission denied SSH", "moved to a new computer", or "cloned repo on another machine".
npx skill4agent add locaweb/cofounder cofounder-ssh-key-rotationREPO_NAME=$(gh repo view --json name -q .name)
# Preview environment
SSH_KEY=~/.ssh/$REPO_NAME
# Other environments (e.g., production)
SSH_KEY=~/.ssh/$REPO_NAME-productiontest -f "$SSH_KEY"authorized_keysREPO_NAME=$(gh repo view --json name -q .name)
# Preview environment
rm -f ~/.ssh/$REPO_NAME ~/.ssh/$REPO_NAME.pub
ssh-keygen -t ed25519 -f ~/.ssh/$REPO_NAME -N "" -C "$REPO_NAME-deploy"
chmod 600 ~/.ssh/$REPO_NAME
# Other environments (e.g., production)
rm -f ~/.ssh/$REPO_NAME-production ~/.ssh/$REPO_NAME-production.pub
ssh-keygen -t ed25519 -f ~/.ssh/$REPO_NAME-production -N "" -C "$REPO_NAME-deploy-production"
chmod 600 ~/.ssh/$REPO_NAME-production# Preview
gh secret set SSH_PRIVATE_KEY < ~/.ssh/$REPO_NAME
# Production (or other environment -- suffix matches env_name uppercased)
gh secret set SSH_PRIVATE_KEY_PRODUCTION < ~/.ssh/$REPO_NAME-production# .github/workflows/rotate-ssh-key-preview.yml
name: Rotate SSH Key Preview
on:
workflow_dispatch:
permissions:
contents: read
jobs:
rotate:
uses: locaweb/locaweb-cloud-provision/.github/workflows/rotate-ssh-key.yml@v1
with:
env_name: "preview"
secrets:
CLOUDSTACK_API_KEY: ${{ secrets.CLOUDSTACK_API_KEY }}
CLOUDSTACK_SECRET_KEY: ${{ secrets.CLOUDSTACK_SECRET_KEY }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}env_nameSSH_PRIVATE_KEY# .github/workflows/rotate-ssh-key-production.yml
name: Rotate SSH Key Production
on:
workflow_dispatch:
permissions:
contents: read
jobs:
rotate:
uses: locaweb/locaweb-cloud-provision/.github/workflows/rotate-ssh-key.yml@v1
with:
env_name: "production"
secrets:
CLOUDSTACK_API_KEY: ${{ secrets.CLOUDSTACK_API_KEY }}
CLOUDSTACK_SECRET_KEY: ${{ secrets.CLOUDSTACK_SECRET_KEY }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY_PRODUCTION }}git add .github/workflows/rotate-ssh-key-preview.yml
git commit -m "Add SSH key rotation workflow for preview"
git push
# Trigger the workflow
gh workflow run rotate-ssh-key-preview.yml# Watch the run
gh run list --workflow=rotate-ssh-key-preview.yml --limit=5
gh run watch <run-id>gh run list --limit=1 --json databaseId,url -q '.[0].url'gh run view <run-id> --log-failedREPO_NAME=$(gh repo view --json name -q .name)
# Get the web IP from the latest deploy run
rm -rf $HOME/tmp/provision-output
gh run list --workflow=deploy-preview.yml --status=success --limit=1
gh run download <run-id> --name provision-output --dir $HOME/tmp/provision-output
cat $HOME/tmp/provision-output/provision-output.json
# Test SSH with the new key
ssh -i ~/.ssh/$REPO_NAME -o ConnectTimeout=10 root@<web_ip> "echo 'SSH rotation successful'"rotate-ssh-key.yml@v1| Input | Type | Default | Description |
|---|---|---|---|
| string | | Environment name (must match the deployed environment) |
| Secret | Description |
|---|---|
| CloudStack API key |
| CloudStack secret key |
| The new SSH private key (already updated in Step 3) |
authorized_keys| Environment | Local key path | GitHub secret |
|---|---|---|
| preview (default) | | |
| production | | |
other | | |