반응형

 

전체 순서

  1. ssh key 생성
  2. public key 복사
  3. public key를 git hub에 등록
  4. 연결 테스트
  5. ssh agent에 만든 key를 등록

 

1. ssh key 생성

아래와 같이 ssh key를 생성합니다. public key와 private key 가 생성됩니다. 진행중에 중간에 passphrase를 입력하는 부분이 있습니다. 여기에서 입력하는 내용을 잘 기억해둘 필요가 있습니다. 나중에 연결 테스트와 에이전트 등록 시에 필요합니다.

$ ssh-keygen -t rsa -b 4096 -C "email_id@gmail.com"

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/userid/.ssh/id_rsa): /Users/userid/.ssh/id_rsa_hub

Enter passphrase (empty for no passphrase): 

Enter same passphrase again: 

Your identification has been saved in /Users/userid/.ssh/id_rsa_hub.

Your public key has been saved in /Users/userid/.ssh/id_rsa_hub.pub.

The key fingerprint is:

SHA256:AqTythcY5Ki0cxu+4/0D6mlhkghx8MxY1ynvPNnN+Vw email_id@gmail.com

The key's randomart image is:

+---[RSA 4096]----+

|..o o. .         |

|.X.+. o          |

|++B .o           |

|+o.o ..          |

|+o=o.o.oSo .     |

|.+++oo=.. +   E  |

|  +o+ ..   o .   |

|   =+  .    o    |

|  +=.....        |

+----[SHA256]-----+
$

 

잘 진행되었다면 아래와 같이 생성된 public key와 private key 파일이 보입니다.

$ ls -al ~/.ssh
-rw-------    1 userid  ugroup   3.4K  8  3 11:04 id_rsa_hub
-rw-r--r--    1 userid  ugroup   746B  8  3 11:04 id_rsa_hub.pub

.ssh/config 파일에 생성된 키와 사용할 호스트 정보를 추가해 줍니다. 아래의 양식/내용과 같습니다. userid와 생성한 파일 이름을 알맞게 바꾸어 주세요.

Host github
  Hostname *.github.com
  User github_userid
  IdentityFile /Users/userid/.ssh/id_rsa_hub

 

2. public key 복사

# 아래의 명령을 이용하여 클립보드에 퍼블릭 키 내용을 복사해 둡니다.

$ pbcopy < ~/.ssh/id_rsa_hub.pub

 

3. public key를 git hub에 등록

git hub에 로그인한 뒤 메뉴를 찾아갑니다. 사용자 아이콘 클릭 -> 설정(Settings) -> access(SSH and GPG keys)  클릭 후  New SSH key 버튼(아래 이미지 내 <==)를 클릭 합니다.

 

그리고 나서 등록화면의 Title에 id_rsa_pub를 입력하고 Key에는 (pbcopy를 통해) 클립보드에 복사해 둔 내용을 붙여 넣습니다.

 

4. 연결 테스트

$ ssh -T git@github.com

Hi user_name! You've successfully authenticated, but GitHub does not provide shell access.

성공적으로 연결되면 아래와 같은 메시지가 나옵니다.

 

5. ssh agent에 만든 key 등록

마지막으로 아래와 같은 명령으로 만들어 놓은 key를 ssh agent에 등록합니다.

$ ssh-add -K ~/.ssh/id_rsa_hub

Enter passphrase for /Users/userid/.ssh/id_rsa_hub: (ssh key 생성시에 입력했던 passphrase를 입력합니다.) 

Identity added: /Users/userid/.ssh/id_rsa_hub (userid@gmail.com)

 

이후부터는 아래와 같은 git clone 명령시 패스워드 입력 없이 진행할 수 있습니다.

$ git clone git@github.com:github_userid/repository_name.git

'repository_name'에 복제합니다...

warning: 빈 저장소를 복제한 것처럼 보입니다.

 

 

 

반응형
반응형

 

 

잘 되던 git 명령어가 안되면서 아래와 같이 403 에러나 발생했다.

$ git push
Password for 'https://githubuser@github.com': 
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: unable to access 'https://githubuser@github.com/githubuser/ler.git/': The requested URL returned error: 403

자세히 보니 패스워드 기반의 인증을 이제 안해 준다는 말........

그래서 제시한 링크로 들어가보니

https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/

 

Token authentication requirements for Git operations | The GitHub Blog

Beginning August 13th, 2021, we will no longer accept account passwords when authenticating Git operations on GitHub.com.

github.blog

위의 링크를 클릭하면 아래와 같은 페이지가 나온다.

 

그리고 아래쪽에 보니 할일이 나와 있다.

 

PAT(Personal Access Token)을 만들어서 사용해야한다는....

a personal access token 링크를 클릭하니 아래와 같은 페이지가 나온다.

https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token

 

Creating a personal access token - GitHub Docs

Personal access tokens (PATs) are an alternative to using passwords for authentication to GitHub when using the GitHub API or the command line. If you want to use a PAT to access resources owned by an organization that uses SAML SSO, you must authorize the

docs.github.com

 

내용을 보면서 하나씩 따라해서 PAT를 만들었다.

 

 

아래 쪽에 만든 PAT의 사용 방법이 나와 있는데 패스워드 대신에 PAT를 입력하면 된다는 내용이다.

 

매번 입력하기 귀찮으니 간단히 캐싱하는 방법이 있는데 아래와 같다.

# 설치 확인
$ git credential-osxkeychain

# osxkeychain 사용 설정
$ git config --global credential.helper osxkeychain

# 사용시간 설정(초)
$ git config --global credential.helper 'cache --timeout=3600'

 

 

반응형

+ Recent posts