티스토리 뷰
1. SSH key 생성
ssh-keygen 명령어로 암호화 방법 중 하나인 ed25519로 ssh-key를 생성한다.
$ ssh-keygen -t ed25519 -C "your_email@example.com"엔터를 치면 기본 저장 위치로 저장이 된다.
> Enter a file in which to save the key (/Users/you/.ssh/id_algorithm): [Press enter]passphrases를 설정할 것인지 물어본다. (passphrases는 비밀번호를 한번 더 장치한다고 생각하면 된다.)
> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]2. ssh-agent 실행
$ eval "$(ssh-agent -s)"
> Agent pid 59566ssh-agent가 개인키를 암호화해서 기억해주기 때문에 매번 입력해야 하는 불필요함을 덜어준다.
3. SSH Host 설정
$ touch ~/.ssh/configconfig 파일에 아래 내용을 적어준다.
Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed255194. SSH agent key 등록
SSH private key를 agent에 등록해준다.
$ ssh-add -K ~/.ssh/id_ed255195. github에 public key 등록
$ pbcopy < ~/.ssh/id_ed25519.pub복사한 public key를 아래와 같이 github에 추가해준다.
Profile > settings > SSH and GPG keys

6. 연결 확인
$ ssh -T git@github.com
# Attempts to ssh to GitHub아래 와 같은 에러가 날 수도 있다.
ssh: connect to host [github.com](http://github.com/) port 22: Connection timed out
가끔 방화벽이 SSH 연결을 차단하기 때문인데 ~/. ssh/config 에 아래 코드를 추가해준다.
Host github.com Hostname ssh.github.com Port 443연결이 성공하면 아래와 같이 나온다.
> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
> RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
> Are you sure you want to continue connecting (yes/no)?여러 계정 사용하기
. ssh/config 수정
# github - Personal
# ------------------------------------
Host github.com-personal
  HostName github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/github-personal
  User Personal
# github - Work
# ------------------------------------
Host github.com-work
  HostName github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/github-work
  User Work연결 확인
$ ssh -T github.com-personal$ ssh -T github.com-workremote 설정
remote url을 config에서 설정한 Host 이름에 맞게 변경해야 한다.
$ git clone git@github.com-personal:Test/test-repo.git
# git clone git@{.ssh/config에서 설정한 Host 이름}:{github repository}Gitconfig 설정
work 폴더에. git이 위치하면 work에 해당하는 gitconfig으로 변경되기를 원할 때 아래와 같이 설정한다.
// ~/.gitconfig
[user]
        name = Personal
        email = personal@test.com
[includeIf "gitdir:~/Desktop/work/"]
        path = ~/.gitconfig-work// ~/.gitconfig-work
[user]
        email = work@test.com
        name = WorkReference
- https://docs.github.com/en/authentication/connecting-to-github-with-ssh
- https://somjang.tistory.com/entry/맥북에서-GitHub-계정-여러개-사용하는-방법
- https://devlog.jwgo.kr/2019/04/17/ssh-keygen-and-ssh-agent/
반응형
    
    
    
  'Tutorial' 카테고리의 다른 글
| brew install 특정 버전 (0) | 2022.01.03 | 
|---|---|
| Mac Setup (0) | 2021.10.18 | 
| 나도 Github 프로필 꾸미기 (0) | 2021.10.11 | 
					댓글
						
					
					
					
				
			
										공지사항
										
								
							
								
								
									최근에 올라온 글
									
							
								
								
									최근에 달린 댓글
									
							
								
								- Total
- Today
- Yesterday
									링크
									
							
								
								
									TAG
									
							
								
								- docker-compose
- 프리온보딩
- pytest
- Complier
- Isolate level
- buildkit
- Network
- user-agent
- 덕타이핑
- HTTP/2
- cka
- direnv
- GitHub
- http
- no-op
- k8s
- 창업
- gitignore
- MSA
- QUIC
- Git
- 위코드
- database
- inflearn
- 원티드
- thetextbook
- web_server
- Python
- go
- HTTP/3
| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | 
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | 
| 26 | 27 | 28 | 29 | 30 | 31 | 
									글 보관함