[GitHub 100일 챌린지] Day 9 - SSH 키 설정
[GitHub 100일 챌린지] Day 9 - SSH 키 설정
100일 챌린지 Day 9 - SSH 키로 더 안전하고 편리하게 인증합니다
배울 내용
- SSH란 무엇인가
- SSH 키 생성하기
- GitHub에 SSH 키 등록하기
Topic1. SSH란 무엇인가
SSH (Secure Shell)의 개념
암호화된 네트워크 프로토콜로 안전하게 통신하는 방법입니다.
1
2
3
4
5
6
7
HTTPS 방식:
git clone https://github.com/user/repo.git
→ 매번 Token 입력 필요
SSH 방식:
git clone git@github.com:user/repo.git
→ 비밀번호/Token 입력 불필요!
SSH vs HTTPS
| 구분 | HTTPS | SSH |
|---|---|---|
| 인증 | Token/비밀번호 | SSH 키 |
| 편의성 | 매번 입력 | 자동 인증 |
| 보안 | 높음 | 매우 높음 |
| 설정 | 쉬움 | 약간 복잡 |
| 방화벽 | 호환성 좋음 | 차단될 수 있음 |
SSH 키 쌍이란?
공개키 + 개인키 한 쌍:
1
2
3
4
5
6
7
8
9
개인키 (Private Key):
- 내 컴퓨터에만 저장
- 절대 공유하면 안됨
- id_rsa 또는 id_ed25519
공개키 (Public Key):
- GitHub에 등록
- 공개해도 안전
- id_rsa.pub 또는 id_ed25519.pub
작동 원리:
1
2
3
4
5
1. GitHub에 공개키 등록
2. Git 명령 실행
3. 내 개인키로 서명
4. GitHub가 공개키로 검증
5. 인증 성공!
Topic2. SSH 키 생성하기
SSH 키 확인
기존 키가 있는지 확인:
1
ls -al ~/.ssh
이미 있는 경우:
1
2
3
4
5
id_rsa
id_rsa.pub
또는
id_ed25519
id_ed25519.pub
파일이 있다면 이미 SSH 키가 있는 것입니다!
SSH 키 생성 (없는 경우)
Ed25519 알고리즘 사용 (권장):
1
ssh-keygen -t ed25519 -C "your-email@example.com"
RSA 알고리즘 사용 (구형 시스템):
1
ssh-keygen -t rsa -b 4096 -C "your-email@example.com"
해보기:
1
2
3
1. 터미널/Git Bash 열기
2. 명령어 입력:
ssh-keygen -t ed25519 -C "your-email@example.com"
키 생성 과정
1. 저장 위치:
1
2
Enter file in which to save the key (/Users/you/.ssh/id_ed25519):
→ 그냥 Enter (기본값 사용)
2. Passphrase (암호):
1
2
3
4
Enter passphrase (empty for no passphrase):
→ 옵션:
- Enter (비워두기, 편리함)
- 암호 입력 (더 안전)
권장: 개인 컴퓨터라면 비워두기, 공용 컴퓨터라면 암호 설정
결과:
1
2
3
4
Your identification has been saved in /Users/you/.ssh/id_ed25519
Your public key has been saved in /Users/you/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx your-email@example.com
SSH Agent에 키 추가
Mac/Linux:
1
2
3
4
5
# SSH agent 시작
eval "$(ssh-agent -s)"
# 키 추가
ssh-add ~/.ssh/id_ed25519
Windows (Git Bash):
1
2
3
4
5
# SSH agent 시작
eval $(ssh-agent -s)
# 키 추가
ssh-add ~/.ssh/id_ed25519
결과: Identity added!
Topic3. GitHub에 SSH 키 등록하기
1단계: 공개키 복사
Mac:
1
pbcopy < ~/.ssh/id_ed25519.pub
Linux:
1
2
cat ~/.ssh/id_ed25519.pub
# 출력된 내용 복사
Windows (Git Bash):
1
cat ~/.ssh/id_ed25519.pub | clip
또는 직접 열기:
1
cat ~/.ssh/id_ed25519.pub
공개키 형태:
1
ssh-ed25519 AAAAC3Nza...나머지키... your-email@example.com
2단계: GitHub에 키 등록
해보기:
1
2
3
4
5
6
1. GitHub 로그인
2. Settings → SSH and GPG keys
3. "New SSH key" 클릭
4. Title: "My Laptop" (구분하기 쉬운 이름)
5. Key: 복사한 공개키 붙여넣기
6. "Add SSH key" 클릭
비밀번호 확인:
1
2
GitHub 비밀번호 입력
→ SSH key added successfully!
3단계: SSH 연결 테스트
테스트 명령:
1
ssh -T git@github.com
첫 연결 시:
1
2
3
4
The authenticity of host 'github.com' can't be established.
...
Are you sure you want to continue connecting (yes/no)?
→ yes 입력
성공 메시지:
1
2
Hi username! You've successfully authenticated,
but GitHub does not provide shell access.
결과: SSH 설정 완료!
SSH URL로 Clone하기
HTTPS URL:
1
https://github.com/username/repo.git
SSH URL:
1
git@github.com:username/repo.git
Clone 예시:
1
git clone git@github.com:username/repo.git
차이점:
1
2
HTTPS: Token 필요
SSH: 자동 인증! (비밀번호 불필요)
기존 Repository URL 변경
HTTPS → SSH로 변경:
1
2
3
4
5
6
7
8
# 현재 URL 확인
git remote -v
# SSH URL로 변경
git remote set-url origin git@github.com:username/repo.git
# 확인
git remote -v
결과: 이제 push/pull 시 비밀번호 입력 불필요!
여러 SSH 키 관리
회사/개인 계정 분리:
~/.ssh/config 파일 생성:
1
2
3
4
5
6
7
8
9
10
11
# 개인 계정
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
# 회사 계정
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
사용:
1
2
3
4
5
# 개인
git clone git@github.com:personal/repo.git
# 회사
git clone git@github-work:company/repo.git
정리
완료 체크:
- SSH의 개념을 이해했다
- SSH 키를 생성했다
- GitHub에 공개키를 등록했다
- SSH 연결 테스트를 완료했다
- SSH로 Repository를 Clone했다
중요: 개인키(id_ed25519)는 절대 공유하지 마세요!
다음: Day 10 - GitHub UI 가이드 →
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.
