GitHub는 SSH로 연결하면 매번 아이디/토큰을 입력하지 않고 push, pull 할 수 있다. GitHub 공식 문서는 SSH 연결 절차를 기존 키 확인 → 새 키 생성 → GitHub 계정에 공개키 등록 → 연결 테스트 순서로 안내한다. 또한 기본 권장 알고리즘으로 Ed25519를 사용하며, Ed25519를 지원하지 않는 레거시 환경에서는 RSA 4096을 대안으로 안내한다. :contentReference[oaicite:0]{index=0}
먼저 기존 키가 있는지 확인한다.
ls -al ~/.ssh보통 아래 같은 파일이 있으면 기존 SSH 키가 있는 것이다.
id_ed25519
id_ed25519.pub
id_rsa
id_rsa.pubGitHub 공식 문서 기준 권장 방식은 Ed25519이다. :contentReference[oaicite:1]{index=1}
ssh-keygen -t ed25519 -C "your_email@example.com"ssh-keygen -t ed25519 -C "example@gmail.com"명령 실행 후 보통 아래를 물어본다.
- 저장 위치
- passphrase 설정 여부
그냥 기본 경로를 쓸 거면 Enter 누르면 된다.
기본 경로 예시:
/home/user/.ssh/id_ed25519Ed25519를 지원하지 않는 환경이면 RSA 4096을 사용할 수 있다. :contentReference[oaicite:2]{index=2}
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"GitHub 공식 문서는 생성한 키를 ssh-agent에 추가하는 절차를 안내한다. :contentReference[oaicite:3]{index=3}
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519passphrase를 설정했다면 여기서 한 번 입력할 수 있다.
GitHub에는 .pub 파일 내용을 등록해야 한다. GitHub 공식 문서는 공개키를 GitHub 계정에 추가해야 SSH 접근이 가능하다고 안내한다. :contentReference[oaicite:4]{index=4}
cat ~/.ssh/id_ed25519.pubtype $env:USERPROFILE\.ssh\id_ed25519.pubcat ~/.ssh/id_ed25519.pub출력된 한 줄 전체를 복사한다.
GitHub 웹에서 아래 순서로 들어간다. GitHub 공식 문서의 계정 설정 흐름이다. :contentReference[oaicite:5]{index=5}
- GitHub 로그인
SettingsSSH and GPG keysNew SSH key또는Add SSH key- Title 입력
- Key 칸에 방금 복사한 공개키 붙여넣기
- 저장
Title은 장치 구분용 이름이다.- 예:
My Desktop,Windows Laptop,WSL-Kali
GitHub 공식 문서는 아래 명령으로 연결 테스트를 안내한다. 처음 연결하면 호스트 신뢰 여부를 물을 수 있다. :contentReference[oaicite:6]{index=6}
ssh -T git@github.comssh -T git@github.com
Hi username! You've successfully authenticated, but GitHub does not provide shell access.저 문구가 나오면 정상이다.
HTTPS로 연결된 저장소라면 SSH URL로 바꿔야 한다.
현재 remote 확인:
git remote -vorigin https://github.com/username/repo.git (fetch)
origin https://github.com/username/repo.git (push)SSH로 변경:
git remote set-url origin git@github.com:username/repo.git다시 확인:
git remote -vorigin git@github.com:username/repo.git (fetch)
origin git@github.com:username/repo.git (push)git push origin main정상 설정이면 비밀번호 대신 SSH 키로 인증된다.
개인 계정, 학교 계정, 서버용 키를 따로 쓰면 ~/.ssh/config를 설정하는 편이 편하다.
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yesHost github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
IdentitiesOnly yes
Host github-school
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_school
IdentitiesOnly yes그 경우 remote도 별칭으로 잡는다.
git remote set-url origin git@github-personal:username/repo.git보통 아래 중 하나다.
- 공개키를 GitHub에 안 올림
ssh-agent에 키를 안 넣음- 다른 키를 잡고 있음
- remote URL이 아직 HTTPS임
확인 명령:
ssh -T git@github.com
git remote -v
ssh-add -l이 경우 ~/.ssh/config에서 IdentityFile과 IdentitiesOnly yes를 명시하는 게 가장 깔끔하다.
GitHub에는 반드시 .pub 파일 내용을 넣어야 한다. GitHub는 OpenSSH 공개키 형식을 요구한다. :contentReference[oaicite:7]{index=7}
ssh-keygen -t ed25519 -C "your_email@example.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub
ssh -T git@github.com
git remote set-url origin git@github.com:username/repo.git