C드라이브의 SSD를 교체한 뒤, gitHub를 사용하려고 하니 push 할 때, 문제가 생겼다.
PS C:\Sparta\Calculator> git push -u origin main
The authenticity of host 'github.com (20.200.245.247)' can't be established.
ED25519 key fingerprint is SHA256:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Could not create directory '/c/Users/rlaxo/.ssh' (Permission denied).
Failed to add the host to the list of known hosts (/c/Users/rlaxo/.ssh/known_hosts).
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
해결 방법 : 공개키를 생성한 뒤, gitHub 계정 설정에 들어가서 공개키를 등록하면 된다.
1. git Bash를 열어서 아래 명령어를 통해 공개키를 생성한다.
$ ssh-keygen -t ed25519 -C "your_email@example.com"
2. 그러면 키를 저장할 파일을 입력하라는 문구가 뜬다. (기본 경로를 이용하려면 그냥 Enter만 치면 된다.)
Enter file in which to save the key (/c/Users/rlaxo/.ssh/~~~~~):
3. 비밀번호 입력 및 재확인
Enter passphrase (empty for no passphrase): 원하는 비밀번호 입력
Enter same passphrase again: 원하는 비밀번호 입력
Your identification has been saved in ~~~~~.
Your public key has been saved in ~~~~~.pub.
4. 공개키 확인 및 복사 (cat 명령어와 ssh 키 값이 저장된 파일 경로를 사용)
나의 경우 저장된 파일의 경로는 /c/Users/rlaxo/.ssh/~~~~~.pub 이다
아래 값을 복사한다. (ssh 부터 본인 이메일까지)
$ cat /c/Users/rlaxo/.ssh/~~~~~.pub
ssh-ed25519 ~~~~~~~~~~~~~~~~삭제~~~~~~~~~~~~~~ rlaxodud214@naver.com
5. github 설정 페이지로 이동
본인 프로필 이미지 클릭 -> Settings -> (Access) SSH and GPG Keys 선택 -> New SSH key 클릭
Title : 본인이 알아볼 수 있도록만 작성하면 된다.
Key : 5번에서 복사한 값을 넣어준다.
다음 Add SSH Key만 누르면 정상적으로 등록된다.
6. 이제 다시 repository에 push를 한다.
PS C:\Sparta\Calculator> git push -u origin main
The authenticity of host 'github.com (20.200.245.247)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Failed to add the host to the list of known hosts (/c/Users/rlaxo/.ssh/known_hosts).
Enter passphrase for key '/c/Users/rlaxo/.ssh/~~~~~':
Enumerating objects: 95, done.
Counting objects: 100% (95/95), done.
Delta compression using up to 20 threads
Compressing objects: 100% (66/66), done.
Writing objects: 100% (95/95), 99.86 KiB | 668.00 KiB/s, done.
Total 95 (delta 4), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (4/4), done.
To github.com:rlaxodud214/NBC-Calculator.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.
중간쯤에 아까 파일에 지정했던 공개키 비밀번호를 입력하라는 문구가 나온다.
-> Enter passphrase for key '/c/Users/rlaxo/.ssh/~~~~~':
3번에서 입력했던 비밀번호를 입력해주면, 이제 제대로 push 되는 것을 볼 수 있다.
참고한 링크 (아래에 있는 더보기 클릭)
기존 SSH 키 확인 - GitHub Docs
SSH 키를 생성하기 전에 기존 SSH 키가 있는지 확인할 수 있습니다.
docs.github.com
새 SSH 키 생성 및 ssh-agent에 추가 - GitHub Docs
SSH(Secure Shell Protocol)를 사용하여 GitHub.com의 리포지토리에서 데이터에 액세스하고 쓸 수 있습니다. SSH를 통해 연결할 때 로컬 머신에서 프라이빗 키 파일을 사용하여 인증합니다. 자세한 내용은 "
docs.github.com
GitHub 계정에 새 SSH 키 추가 - GitHub Docs
GitHub.com에서 새로운 (또는 기존) SSH 키를 사용하도록 계정을 구성하려면, 계정에 키도 추가해야 합니다.
docs.github.com