Automate checking who has access to GitHub repositories using shell scripting and GitHub API.
Problem: When an employee leaves, you need to check 50+ repositories manually to see if they have access. Takes 1 hour.
Solution: This script checks all repositories automatically in 2 minutes.
├── README.md (This file - complete guide)
├── LEARN_BASH_BASICS.md (Learn bash symbols and concepts)
├── list-users.sh (Main script)
└── test-connection.sh (Test script)
- Go to: https://github.com/settings/tokens
- Click "Generate new token (classic)"
- Name:
DevOps API - Check boxes:
repoandread:org - Click "Generate token"
- Copy the token (starts with
ghp_)
- Go to: https://github.com/new
- Name:
test-repo - Make it Public
- Check "Add a README file"
- Click "Create repository"
# Install tools (Ubuntu/EC2)
sudo apt update
sudo apt install curl jq -y
# Make scripts executable
chmod +x *.sh
# Set credentials (replace with YOUR values)
export username=YOUR_GITHUB_USERNAME
export token=ghp_YOUR_TOKEN
# Test connection
./test-connection.sh
# Run main script
./list-users.sh YOUR_USERNAME test-repo========================================
Testing GitHub API Connection
========================================
✓ Credentials are set
Username: Pavan143Kundeti
Token: ghp_abc123...
✓ Connecting to GitHub API...
✓ Connection successful!
Your GitHub Info:
Username: Pavan143Kundeti
Name: Pavan Kundeti
Public Repos: 5
✓ You're ready to use the main script!
========================================
GitHub Repository Access Checker
========================================
Fetching users with access to: Pavan143Kundeti/test-repo
Users with access:
------------------
Pavan143Kundeti
alice
bob
Total users: 3
========================================
- You run the script with repository name
- Script calls GitHub API using your token
- GitHub sends back JSON data with user list
- Script extracts usernames using jq
- Script displays results
Behind the scenes:
# Script does this:
curl -u "username:token" https://api.github.com/repos/owner/repo/collaborators
# GitHub returns JSON:
[{"login": "Pavan143Kundeti"}, {"login": "alice"}]
# Script extracts usernames:
Pavan143Kundeti
alicechmod +x *.shsudo apt install jq -y# Check your token
echo $token
# If empty, set it again
export token=ghp_YOUR_TOKENexport username=YOUR_USERNAME
export token=ghp_YOUR_TOKEN./list-users.sh mycompany payment-service | grep bobecho "Audit Report - $(date)" > audit.txt
./list-users.sh mycompany payment-service >> audit.txt
./list-users.sh mycompany user-service >> audit.txt
cat audit.txtRead LEARN_BASH_BASICS.md to understand every symbol and concept used in the scripts.
Topics covered:
- Variables (
$name,${name}) - Tests (
[ -z "$var" ],[ $a -gt $b ]) - Logic (
||OR,&&AND) - Arguments (
$1,$2,$#) - Paths (
.,..,~,/) - Pipes (
|) - Redirects (
>,>>) - curl flags (
-s,-u) - Command substitution (
$(command))
✅ GitHub Personal Access Tokens ✅ REST API calls with curl ✅ JSON parsing with jq ✅ Shell scripting automation ✅ Error handling ✅ Real DevOps use case
# Setup
sudo apt install curl jq -y
chmod +x *.sh
export username=YOUR_USERNAME
export token=ghp_YOUR_TOKEN
# Run
./test-connection.sh
./list-users.sh YOUR_USERNAME test-repo
# Check credentials
echo $username
echo $tokenTime to Complete: 15-30 minutes
Difficulty: Beginner-Friendly
Skills: Shell scripting, APIs, JSON, DevOps
🎉 Congratulations! You've completed a real DevOps automation project!