서론
로컬에서 GitHub에 push 하려고 할 때마다 자꾸 비밀번호를 물어보는 게 너무 귀찮았고 Jetbrains 시리즈는 자동 연결해 주지만 터미널 명령어로 쓰려면 SSH 연결을 해야 하더라.
그래서 SSH 연결 방식으로 바꾸기로 했고, 드디어 성공해서 블로그에 기록해 둔다.
(Mac 기준으로 작성되었고, 에디터 관계없이 적용된다.)
본문
준비
- GitHub 계정( 계정별로 SSH Key 생성가능)
- Git CLI (git --version으로 설치 확인)
- macOS (터미널 사용)
1. Git 사용자 정보 등록
ssh key 계정 생성 시 터미널 실행 위치는 상관없음.
- user.name : 깃 커밋 히스토리에 나오는 "작성자 이름”
- user.email : “작성자 이메일” 깃허브 계정 이메일과 일치하면 자동으로 커밋에 프로필 연결됨
git config --global user.name "myname"
git config --global user.email "myemail@gmail.com"
2. SSH 키 생성
ssh-keygen -t ed25519 -C "myemail@gmail.com"
- ed25519 타입이 요즘 권장되는 방식
- 저장 위치는 기본값 (/Users/사용자명/. ssh/id_ed25519)으로 엔터
- passphrase는 생략해도 되고, 보안 위해 입력해도 돼요!
Result
user ~ % ssh-keygen -t ed25519 -C "myemail@email.com"
Generating public/private ed25519 key pair.
Enter passphrase for "/Users/xxxx/.ssh/id_ed25519" (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/xxxx/.ssh/id_ed25519
Your public key has been saved in /Users/xxxx/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:blablablasc
The key's randomart image is:
+--[ED25519 256]--+
| |
| |
| xxxxxxxxx |
+----[SHA256]-----+
3. SSH 에이전트 실행 & 키 등록
- 계정 한 개 등록 시 “id_ed25519”
- 계정 여러 개 등록 “id_ed25519_company” or “id_ed25519_myemail”
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Result
Agent pid xxxx
Identity added: /Users/xxxx/.ssh/id_ed25519 (myemail@email.com)
user@MacBook-Pro ~ %
4. 공개키 GitHub 등록
아래 명령어를 터미널에 입력하면
- pbcopy는 macOS에서 자동으로 클립보드로 복사
- 메모장에 붙여 넣어보면 “ssh-ed25519 xxxx” 클립보드에 저장되어 있음
pbcopy < ~/.ssh/id_ed25519.pub
5. SSH and GPG keys GitHub에 붙여 넣기
- GitHub → Settings → SSH and GPG keys → New SSH key → 이름 적당히 붙이고 붙여 넣기
- 링크로 접속하고 바로 로그인해도 됨 https://github.com/settings/keys
GitHub · Build and ship software on a single, collaborative platform
Join the world's most widely adopted, AI-powered developer platform where millions of developers, businesses, and the largest open source community build software that advances humanity.
github.com
5.1 GitHub → Settings
5.2 GitHub → Settings → SSH and GPG keys 메뉴 클릭
5.3 GitHub → Settings → SSH and GPG keys → New SSH key 버튼클릭
5.4 GitHub → `Settings` → `SSH and GPG keys` → `New SSH key`
- title : 이름 작성
- key : 터미널에서 복사된 키 붙어 넣기
- Add SSH key 붙여 넣기
6. 연결 테스트
ssh -T git@github.com
이 메시지가 나오면 성공!
Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access.
7. 리포지토리 주소 복사 및 변경 (https → ssh)
7.1 리포지토리 주소 복사
7.2 위에서 복사한 주소를 붙여 넣어 주소 변경한다
git remote set-url origin git@github.com:사용자명/저장소명.git
8. push 테스트
git add 파일명.py
git commit -m "Test push via SSH"
git push origin main
마무리
처음에 약간 복잡해 보여도, 딱 한 번만 해두면 편하게 push/pull 할 수 있어요.
당분간은 git push 하고 아무 반응 없으면 성공한 거예요 ㅎㅎ
궁금한 거 있으면 댓글로 남겨주세요!
'Dev > ETC. Dev' 카테고리의 다른 글
GitHub에 잘못 올린 파일 삭제하는 방법 (feat. .vscode, .history) (1) | 2025.04.29 |
---|---|
RESTful API 설계가 답일까? 기능 중심 URL로 바꾸기까지의 기록 (0) | 2025.04.13 |
UUID 버전별 차이와 사용법 정리 (0) | 2025.04.09 |
[DB] UUID를 사용한 고유한 ID 시스템의 장점과 적용 방법 (0) | 2025.03.23 |
[Database] 고유키(Unique Key)와 주키(Primary Key)의 차이 (0) | 2025.03.15 |