GrepBoard/매뉴얼
605 편 ·

GitHub Permission denied (publickey) 해결

·시험 환경 Ubuntu 24.04 (Docker) · OpenSSH 9.6p1 · git 2.43.0 · 2026-10·시험 범위 ↓·6 단계

git@github.com Permission denied (publickey) 는 등록된 키를 ssh 가 내밀지 못한 것입니다. ssh -vT 로 시도한 키를 보고 키·에이전트·사용자를 가립니다.

output
git@github.com: Permission denied (publickey).fatal: Could not read from remote repository. Please make sure you have the correct access rightsand the repository exists.

GitHub 가 공개 키 인증만 받는데, ssh 가 내민 키 중 계정에 등록된 것이 없었다는 뜻입니다. ssh -vT git@github.com 으로 실제로 시도한 키 파일을 보고, 키가 없으면 만들어 등록하고, 있으면 에이전트·파일 이름·sudo 를 확인합니다. 서버 쪽 sshd 를 직접 운영하다 같은 문구를 만났다면 SSH Permission denied (publickey) 원인 찾기를 봅니다. 이 글은 GitHub 에 접속하는 클라이언트 쪽입니다. SSH 대신 HTTPS 주소(https://github.com/…)로 쓰다가 비밀번호가 거절됐다면 password authentication was removed 해결을 봅니다.

[1] git 을 빼고 ssh 만으로 시험합니다. 결과가 같으면 저장소 권한이 아니라 인증 문제입니다.

console
$ ssh -T git@github.com; echo "exit=$?"git@github.com: Permission denied (publickey).exit=255

성공하면 Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access. 가 나옵니다(공식 문서). 이 문구가 나오는데 git clone 만 실패한다면 그 계정에 저장소 접근 권한이 없거나 원격 주소가 틀린 것입니다.

[2] 사용자 이름이 git 인지 봅니다. GitHub 는 모든 SSH 연결을 git 사용자로 받습니다. 원격 주소가 내아이디@github.com:… 이면 키가 맞아도 거절됩니다.

console
$ git remote -v

주소가 git@github.com:<계정>/<저장소>.git 모양이 아니면 git remote set-url origin git@github.com:<계정>/<저장소>.git 로 고칩니다.

[3] ssh 가 어떤 키를 시도했는지 봅니다. 키가 하나도 없는 환경의 결과입니다.

console
$ ssh -vT git@github.com 2>&1 | grep -E "Connecting to|identity file|Authentications that can continue|Trying private key|Offering|No more authentication|Permission denied"debug1: Connecting to github.com … port 22.debug1: identity file /root/.ssh/id_rsa type -1debug1: identity file /root/.ssh/id_rsa-cert type -1…debug1: identity file /root/.ssh/id_ed25519 type -1…debug1: Authentications that can continue: publickeydebug1: Trying private key: /root/.ssh/id_rsa…debug1: Trying private key: /root/.ssh/id_dsadebug1: No more authentication methods to try.git@github.com: Permission denied (publickey).

읽는 법은 이렇습니다.

보이는 것뜻
identity file … type -1 · Trying private key 만 있고 Offering public key 가 없음그 경로에 키 파일이 없습니다. ssh 는 기본 이름 7가지만 찾습니다
Offering public key: … 뒤에 바로 다음 키로 넘어감키는 내밀었지만 GitHub 계정에 등록되지 않은 키입니다
경로가 /root/.ssh/…sudo git … 처럼 root 로 실행했습니다. 내 계정의 키를 쓰지 않습니다
Connecting to … port 22 에서 멈춤인증 전 단계입니다. 22번 포트가 막혔을 수 있습니다 — [6]

GitHub 문서도 sudo 로 git 을 쓰지 말라고 합니다. sudo 없이 만든 키는 sudo git push 에서 쓰이지 않습니다.

[4] 키 이름이 기본값과 다르면 직접 지정합니다. ssh 가 자동으로 찾는 파일은 아래 목록뿐입니다.

console
$ ssh -G github.com | grep -E "^(user|hostname|port|identityfile|identitiesonly) "…user roothostname github.comport 22identitiesonly noidentityfile ~/.ssh/id_rsaidentityfile ~/.ssh/id_ecdsaidentityfile ~/.ssh/id_ecdsa_skidentityfile ~/.ssh/id_ed25519identityfile ~/.ssh/id_ed25519_skidentityfile ~/.ssh/id_xmssidentityfile ~/.ssh/id_dsa

~/.ssh/github_work 처럼 다른 이름으로 만들었다면 한 번은 ssh -i ~/.ssh/github_work -T git@github.com 으로 시험하고, 되면 설정 파일에 적습니다. 계정이 여러 개라 키가 여러 개면 IdentitiesOnly yes 로 지정한 키만 내밀게 합니다.

~/.ssh/config
Host github.com    User git    IdentityFile ~/.ssh/github_work    IdentitiesOnly yes

[5] 에이전트에 키가 올라가 있는지 봅니다. 에이전트가 없을 때와 비어 있을 때 문구가 다릅니다.

console
$ ssh-add -lCould not open a connection to your authentication agent.$ eval "$(ssh-agent -s)"Agent pid 2772$ ssh-add -lThe agent has no identities.

비어 있으면 ssh-add ~/.ssh/<키 파일> 로 올립니다. 그래도 Offering 한 키가 거절되면 그 키의 공개 키(.pub)가 GitHub 계정의 Settings → SSH and GPG keys 에 있는지 지문으로 대조합니다. ssh-add -l -E sha256 이 찍는 SHA256:… 값과 GitHub 화면의 값이 같아야 합니다. 키가 아예 없으면 ssh-keygen -t ed25519 -C "user@example.com" 으로 만들어 .pub 내용을 등록합니다.

[6] 22번 포트가 막힌 망이면 443 으로 시험합니다. 호스트 이름이 ssh.github.com 으로 바뀝니다. 처음 접속하면 호스트 키를 믿을지 묻습니다. **yes 를 치기 전에** 화면의 지문을 GitHub 가 공개한 지문과 맞춰 봅니다. Ed25519 공개 지문은 SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU 입니다. 다르면 no 로 끊습니다.

console
$ ssh -T -p 443 git@ssh.github.com; echo "exit=$?"The authenticity of host '[ssh.github.com]:443 ([…]:443)' can't be established.ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.This key is not known by any other names.Are you sure you want to continue connecting (yes/no/[fingerprint])? yesWarning: Permanently added '[ssh.github.com]:443' (ED25519) to the list of known hosts.git@ssh.github.com: Permission denied (publickey).exit=255

여기서 Permission denied (publickey) 가 나왔다면 443 으로는 서버까지 닿았다는 뜻이고, 남은 문제는 키입니다. 443 이 되면 공식 문서대로 Host github.com 에 Hostname ssh.github.com · Port 443 을 넣어 씁니다.

대조하지 않고 yes 를 눌렀거나 지문이 의심스러우면 저장된 항목을 보고, 그 호스트 하나만 지운 뒤 다시 접속해 대조합니다.

console
$ ssh-keygen -lf ~/.ssh/known_hosts256 SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU |1|nugbYmhGm+W3/cpmCpjXi8jCVV0=|fhz6rViCQ/TCwEgaqbuiH/2SaZA= (ED25519)$ ssh-keygen -R '[ssh.github.com]:443'# Host [ssh.github.com]:443 found: line 1/root/.ssh/known_hosts updated.Original contents retained as /root/.ssh/known_hosts.old

지문이 다르다는 경고가 나오면 이 글이 아니라 REMOTE HOST IDENTIFICATION HAS CHANGED를 봅니다. 키 파일 권한 경고(UNPROTECTED PRIVATE KEY FILE)가 함께 나오면 그 글부터 고칩니다.

공식 근거: GitHub — Error: Permission denied (publickey) · Using SSH over the HTTPS port · GitHub's SSH key fingerprints

auth.log (SSH) 로그를 브라우저에서 바로 분석 ↗ — 아무것도 올라가지 않습니다.

ssh_config 만들기 도구로 바로 확인 ↗ — 브라우저 안에서 계산합니다.

#git#github#ssh#ssh-agent