Skip to content

Instantly share code, notes, and snippets.

@eriktdesign
Created July 31, 2026 13:46
Show Gist options
  • Select an option

  • Save eriktdesign/109989a763c0da6801f715545a007a87 to your computer and use it in GitHub Desktop.

Select an option

Save eriktdesign/109989a763c0da6801f715545a007a87 to your computer and use it in GitHub Desktop.
Find github users with access to repositories
#!/bin/bash
# Check if a username was provided as the first argument
if [ -z "$1" ]; then
echo "Error: No username provided."
echo "Usage: $0 <username>"
exit 1
fi
TARGET_USER="$1"
echo "Fetching all accessible repositories (this may take a moment)..."
# Use the /user/repos endpoint which grabs EVERYTHING you have access to.
# --paginate automatically grabs all pages so nothing is missed.
# .full_name returns the string in 'owner/repo' format.
REPOS=$(gh api --paginate /user/repos -q '.[].full_name')
echo "Auditing access for $TARGET_USER..."
echo "----------------------------------------"
for REPO in $REPOS; do
# The permissions endpoint returns their effective access level (admin, write, read, none)
PERMISSION=$(gh api "repos/$REPO/collaborators/$TARGET_USER/permission" --jq '.permission' 2>/dev/null)
if [[ -n "$PERMISSION" && "$PERMISSION" != "none" && "$PERMISSION" != "read" ]]; then
echo "⚠️ Found in: $REPO [Access Level: $PERMISSION]"
# ==========================================================
# DANGER ZONE: Uncomment the line below to automatically
# remove their access when the script runs.
# ==========================================================
# gh api --method DELETE "repos/$REPO/collaborators/$TARGET_USER" --silent && echo " -> Access Revoked!"
fi
done
echo "----------------------------------------"
echo "Audit complete."
@eriktdesign

Copy link
Copy Markdown
Author

This script can be used to find users with write access to repositories that you also have access to. Useful for developer offboarding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment