Does anyone have insight on how to create a list of SSH tokens, personal access tokens by user name in Bitbucket Data Center 9.4.18? I've tried several SQL scripts found online with AI but nothing works or produces data. Rest API maybe?
Any help would be welcome.
Hello @GSHerber
Yep, for this stop chasing SQL and use the supported REST endpoints instead.
Also one small wording point: in Bitbucket DC these are SSH keys, not really “SSH tokens”.
For the two user-level items you want, Atlassian documents these endpoints:
- personal HTTP tokens:
GET /rest/access-tokens/latest/users/{userSlug}
- personal SSH keys:
GET /rest/ssh/latest/keys?userName={userName}
One thing to watch for, I found a related Community thread where someone queried the SSH endpoint and got an empty result, so I would test the SSH call with a known user first before you build the full report.
Hi
For Bitbucket Data Center 9.4.18, the REST API is your best bet, as previously suggested by Arkadiusz Wroblewski. Here's how to approach it:
SSH Keys
Use the REST API endpoint:
GET /rest/ssh/1.0/keys?user={username}
To list all users' SSH keys, you can iterate over users:
# Get all users first
curl -u admin:password "https://your-bitbucket.com/rest/api/latest/admin/users?limit=1000"
# Then for each user, get their SSH keys
curl -u admin:password "https://your-bitbucket.com/rest/ssh/1.0/keys?user={username}"
Personal Access Tokens (HTTP Access Tokens)
For PATs, use:
# List all tokens for a specific user (requires admin)
curl -u admin:password "https://your-bitbucket.com/rest/access-tokens/1.0/users/{username}"
Script to List All Users' Tokens
#!/bin/bash
BASE_URL="https://your-bitbucket.com"
AUTH="admin:password"
# Get all users (paginate if needed)
users=$(curl -s -u "$AUTH" "$BASE_URL/rest/api/latest/admin/users?limit=1000" | jq -r '.values[].name')
echo "User,SSH Keys,Access Tokens"
for user in $users; do
ssh_count=$(curl -s -u "$AUTH" "$BASE_URL/rest/ssh/1.0/keys?user=$user" | jq '.size')
pat_count=$(curl -s -u "$AUTH" "$BASE_URL/rest/access-tokens/1.0/users/$user" | jq '.size')
echo "$user,$ssh_count,$pat_count"
done
I hope this helps.
Regards,
Mehul
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.