SSH 키로 Github 레포 연결하기
Github 레포 연결 전 SSH 키를 Github 호스팅 업체로 먼저 등록하였다.
윈도우10 부터 지원하는 SSH Client 설치하고 SSH 키로 비공개한 레포지토리를 연결하고자 한다.
SSH Client 설치 확인
윈도우 10부터는 설정 -> 시스템 -> 선택적 기능 화면에서 OpenSSH 설치되어있는지 확인한다. 기능이 없다면 상단의 기능 추가로 OpenSSH 클라이언트를 설치한다.
Github 에서 OpenSSH 파워쉘 활성화 방법이 제시되어 있다.
# start the ssh-agent in the background
Get-Service -Name ssh-agent | Set-Service -StartupType Manual
Start-Service ssh-agent
SSH config 파일 설정
윈도우 OpenSSH 클라이언트는 config 파일이 없으므로 만들어준다.
config 파일은 C:\\Users\\{UserName}\\.ssh\\
경로로 생성한다.
그리고 본인의 id_rsa 비밀키도 함께 저장한다.
config
Host github.com:kiioio
HostName github.com
user git
IdentityFile C:\\Users\\kiio\\.ssh\\id_rsa
Github SSH 연결 확인하기
다음 명령어로 정상적으로 연결되는지 확인한다.
PS C:\Users\kiioio> ssh -T git@github.com
Hi kiioio! You've successfully authenticated, but GitHub does not provide shell access.
키가 잘못된 경우
Load key "C:\Users\kiioio/.ssh/id_rsa": invalid format
에러가 발생한다면 키가 잘못된 것이다.
로컬 컴퓨터에서 Github 설정하기

링크의 git 설치한 다음 파워 쉘에서 신규 레포지토리로 작업하도록 한다.
git 유저 등록
git config --local user.email "{이메일}"
git config --local user.name {UserName}
신규 레포지토리인 경우 git 원격 설정
git remote add origin git@github.com:kiioio/HelloWorld.git
작업중인 레포지토리인 경우 git 원격 설정
git remote set-url origin git@github.com:kiioio/HelloWorld.git
전체 작업 미리보기
PS C:\Users\kiioio> mkdir HelloWorld
PS C:\Users\kiioio> cd HelloWorld
PS C:\Users\kiioio\HelloWorld> echo "# HelloWorld" >> README.md
PS C:\Users\kiioio\HelloWorld> git init
PS C:\Users\kiioio\HelloWorld> git add .\README.md
PS C:\Users\kiioio\HelloWorld> git commit -m 'first commit'
PS C:\Users\kiioio\HelloWorld> git config --local user.email "kiioio@kiio.com"
PS C:\Users\kiioio\HelloWorld> git config --local user.name kiioio
PS C:\Users\kiioio\HelloWorld> git remote add origin git@github.com:kiioio/HelloWorld.git
PS C:\Users\kiioio\HelloWorld> git push -u origin master
git push 명령어에서 SSH 키가 잘못 된 경우
PS C:\Users\kiio\git> git push -u origin master
Load key "/c/Users/kiio/.ssh/id_rsa": error in libcrypto
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
ssh -T git@github.com
명령어에서 정상적으로 연결되었는데, 여기서 에러가 발생한 경우 id_rsa 키를 지원하지 않는 가능성이 크다. 해당 키를 PEM 포맷으로 변경할 필요가 있다.
ssh-keygen -p -m PEM -f ~/.ssh/id_rsa