개발/Git, GitHub
Git Bash - SSH 키 삭제, 생성, 등록
피로물든딸기
2022. 7. 15. 20:00
반응형
깃허브 데스크탑으로 프로젝트 관리하기 강의 오픈!! (인프런 바로가기)
ssh-keygen 명령어로 SSH 키를 생성할 수 있다.
하지만 과거에 만든 적이 있다면 id_rsa already exists. 경고가 나타난다.
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/bloodstarwberry/.ssh/id_rsa):
/c/Users/bloodstarwberry/.ssh/id_rsa already exists.
Overwrite (y/n)?
overwrite도 가능하지만 SSH 키를 삭제해도 된다.
방법은 Git Bash에서 홈 탭에 있는 .ssh 폴더를 삭제하면 된다.
@ MINGW64 ~
$ rm -rf .ssh
생성된 키가 없는 경우 ssh-keygen을 하면 아래와 같이 키가 만들어진다.
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/bloodstrawberry/.ssh/id_rsa):
Created directory '/c/Users/bloodstrawberry/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/bloodstrawberry/.ssh/id_rsa
Your public key has been saved in /c/Users/bloodstrawberry/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:Z3atAHSt9XjtG67QOuyFvKNeQszCmb/Pr3UjsI bloodstrawberry@bloodstrawberry
The key's randomart image is:
+---[RSA 3072]----+
| . oE . |
| . .. * |
| .. + + . |
| . *.. ..o .|
| *S==..... |
| =+oo=. ..|
| o.*.=.oo|
| =+* oo.|
| .++B=o. |
+----[SHA256]-----+
id_rsa가 private key, id_rsa.pub가 public key가 된다.
Your identification has been saved in /c/Users/bloodstrawberry/.ssh/id_rsa
Your public key has been saved in /c/Users/bloodstrawberry/.ssh/id_rsa.pub
.ssh 폴더에서 ls -al로 확인할 수 있다.
$ ls -al
total 33
drwxr-xr-x 1 KJH 197121 0 7월 13 21:37 ./
drwxr-xr-x 1 KJH 197121 0 7월 13 21:37 ../
-rw-r--r-- 1 KJH 197121 2590 7월 13 21:37 id_rsa
-rw-r--r-- 1 KJH 197121 561 7월 13 21:37 id_rsa.pub
cat을 이용하여 key를 확인한 후 복사하자.
$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAAD...
그리고 깃허브에서 프로필 → [Settings]로 들어간다.
[SSH and GPG keys] → [New SSH Key]로 들어간다.
Add SSH key를 누르면 키가 등록이 된다.
반응형