새소식

사용팁/System Digging

[openwrt] github clone 시 ssh 방식으로 받도록 설정하기

  • -

pc 에서 생성한 8192B rsa 키를 openwrt 의 .ssh 에다 넣고 git clone git@github.com:simryang/vimrc.git 을 실행했더니 권한이 없어서 안된다는 메시지가 출력됩니다.

root@wizfi630s:~# git clone git@github.com:simryang/vimrc.git
Cloning into 'vimrc'...

/usr/bin/ssh: Connection to git@github.com:22 exited: No auth methods could be used.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

그래서 id, pw 를 입력해야 하는 귀찮음을 무릅쓰고 일단은 https 를 사용하고 있었는데 너무나 귀찮아서 찾아보니 GIT_SSH 를 정의해놓으면 git 을 호출할 때마다 특정 키를 사용할 수 있도록 지정할 수 있다고 합니다.

일단 테스트로 dropbearkey -y -f ~/.ssh/id_rsa 를 실행해봤습니다만..

root@wizfi630s:~# dropbearkey -y -f ~/.ssh/id_rsa
Exited: String too long

키가 너무 길어서 안된답니다...

그래서 기존 키를 지우고 키부터 다시 생성했습니다.

root@wizfi630s:~# rm ~/.ssh/id_rsa*
root@wizfi630s:~# dropbearkey -t rsa -f ~/.ssh/id_rsa
Generating 2048 bit rsa key, this may take a while...

엄청 오래 걸립니다. 다른 일을 하고 오시면 다음과 같은 메시지를 보면 정상적으로 생성된 것입니다.

Public key portion is:
ssh-rsa AAAAB(중략)Abc root@wizfi630s
Fingerprint: sha1!! aa:bb:cc:중략:dd

여기에서 Public key portion is: 줄과 Fingerprint 줄을 제외한 그 사이의 ssh-rsa로 시작하는 것을 복사합니다.

이 내용을 github의 Settings >> SSH and GPG keys >> New SSH key 를 실행해서 붙여넣으시면 됩니다. 제목은 무슨 키인지 알 수 있도록 적당히 적어줍니다.

하지만 여전히 git clone 은 실패합니다. 이제는 GIT_SSH 를 정의 및 적용할 때입니다.

root@wizfi630s:~# echo "#!/bin/sh" > ~/.gitssh.sh
root@wizfi630s:~# echo "dbclient -y -i ~/.ssh/id_rsa \$*" >> ~/.gitssh.sh
root@wizfi630s:~# chmod +x ~/.gitssh.sh
root@wizfi630s:~# echo "export GIT_SSH=\$HOME/.gitssh.sh" >> /etc/profile

이제 Ctrl+D 키를 여러번 눌러 로그아웃 하셨다가 엔터키 누르고 다시 로그인을 하시든, 재부팅을 하시든지 해보세요. 부팅 및 로그인이 완료되었으면 다음처럼 저장소를 clone 해봅시다!!

root@wizfi630s:~# git clone git@github.com:simryang/vimrc.git
Cloning into 'vimrc'...
remote: Enumerating objects: 6, done.
...중략...
Resolving deltas: 100% (2/2),done.

잘 되네요 :)

Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.