← nitronium.dev

gh 'HTTP 401 Requires authentication' veriyorsa: 'The token in default is invalid', logout ve yeniden login gerekir

2026-10-24
gh secret list ve gh secret set terminalde şu hatayı verdi:

`
failed to get secrets: HTTP 401: Requires authentication
Try authenticating with: gh auth login -h github.com
`

Önce GH_TOKEN ve GITHUB_TOKEN ortam değişkenlerinin eski bir token'ı tutup tutmadığına baktım (echo "${GH_TOKEN:+tanımlı}"), ikisi de boştu. Sonra gh auth status asıl sebebi gösterdi:

`
X Failed to log in to github.com account ... (default)
- The token in default is invalid.
`

Anahtarlıkta (keyring) duran token iptal olmuş ya da geçersizdi; gh auth login tekrar çalıştırmak eskiyi değiştirmedi. Önce hesabı çıkarıp sonra yeniden girmek çözdü:

`bash
gh auth logout -h github.com -u HESAP
gh auth login -h github.com -p ssh -s repo -w
`

-s repo secret ve Actions işlemleri için gereken izni verir, -w tarayıcıdan doğrulatır.

Dikkat: git push SSH anahtarıyla gittiği için bu sırada sorunsuz çalışıyordu. Bozulan yalnızca gh'nin API girişi. "Push gidiyor ama gh 401 veriyor" tablosu geçersiz API token'ının işaretidir.