프로그래밍/기타
github ssh 설정
chance
2022. 9. 2. 13:12
ssh 키 생성
ssh-keygen -t rsa -C "comment: email or something"
공개키 등록
공개키(pub) 파일내용을 github > Settings > SSH and GPG Keys 에서 ssh 키 등록
config 생성
host는 실제가 아닌 구분을 위한 이름으로 remote 등록시에 사용된다.
Host id1.github.com
HostName github.com
IdentityFile ~/.ssh/개인키1_파일명
User git
Host id2.github.com
HostName github.com
IdentityFile ~/.ssh/개인키2_파일명
User git
Port 22
git remote 등록
SSH를 사용하는 경우 http와는 다른 url 형식 사용
git@host 중 host는 실제 도메인이 아닌 config에 정의한 Host 를 기반으로 설정됨
22번 포트 사용 여부에 따라 url 구성이 달라짐
ex) github 계정: account, 저장소: repo, config의 host: id1.github.com 인 경우
git@id1.github.com:account/repo.git
ssh://git@id1.github.com:port/account/repo.git
SSH 키 등록
매번 비밀번호 입력을 하지 않기위해 생성한 키를 ssh 에이전트, 키체인에 등록
에이전트에 등록
등록: ssh-add ~/.ssh/개인키파일
확인 : ssh-add -l
삭제: ssh-add -d 개인키파일
맥 키체인 등록(12.0 monterey)
맥의 경우 개인키 정보를 키체인에 등록할 수 있다.
ssh-add --apple-use-keychain ~/.ssh/개인키파일
config 수정
config에 키체인, 에이전트 등록 여부를 추가
UseKeychain yes
AddKeysToAgent yes
Host id1.github.com
HostName github.com
IdentityFile ~/.ssh/개인키1_파일명
User git
UseKeychin yes
AddKeysToAgent yes
Host id2.github.com
HostName github.com
IdentityFile ~/.ssh/개인키2_파일명
User git
Port 22
UseKeychin yes
AddKeysToAgent yes
SSH 암호변경
ssh-keygen -p -f ~/.ssh/개인키파일
기존 암호를 잃어버린경우엔 키체인에 등록해둔 경우에만 변경가능
키체인 > ssh > 해당 항목 더블클릭 > 암호보기