Created
July 31, 2026 13:46
-
-
Save eriktdesign/109989a763c0da6801f715545a007a87 to your computer and use it in GitHub Desktop.
Find github users with access to repositories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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." |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script can be used to find users with write access to repositories that you also have access to. Useful for developer offboarding.