github를 접근할 때 매번 패스워드를 사용하기 싫을 경우
아래와 같이 ssh key를 미리 등록 해 놓는 방법이 있다.
(.pia-aws) ec2-user:~/environment/DevOps_Microservices (main) $ ssh-keygen -t rsa
Generating public/private rsa key pair.
해당 명령어를 실행 하면 아래와 같이 특정 디렉토리에 ssh 키가 만들어진다.
Enter file in which to save the key (/home/ec2-user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ec2-user/.ssh/id_rsa.
Your public key has been saved in /home/ec2-user/.ssh/id_rsa.pub.
The key fingerprint is:
여기서는
`id_rsa.pub.`
이다.
cat으로 해당 데이터를 열어보자
(.pia-aws) ec2-user:~/environment/DevOps_Microservices (main) $ cat /home/ec2-user/.ssh/id_rsa.pub
아래와 같이 공개키를 확인 가능하다
ssh부터 intenal까지 모두 copy 한다
이를
github의 Settings => SSH => New SSH key에
등록하면 된다.
그런데 문제는 이미 clone을 한번 받은 상태에서 처리다.
remote의 url이 https를 경유하게 됨으로 rsa를 등록한다고 해도 ssh를 사용하지 않게된다.
(.pia-aws) ec2-user:~/environment/DevOps_Microservices (main) $ git remote -v
origin https://github.com/theyoung/Containerization.git (fetch)
origin https://github.com/theyoung/Containerization.git (push)
(.pia-aws) ec2-user:~/environment/DevOps_Microservices (main) $ git remote set-url origin git@github.com:theyoung/Containerization.git
(.pia-aws) ec2-user:~/environment/DevOps_Microservices (main) $ git remote -v
origin git@github.com:theyoung/Containerization.git (fetch)
origin git@github.com:theyoung/Containerization.git (push)
(.pia-aws) ec2-user:~/environment/DevOps_Microservices (main) $ git commit -m 'test' Dockerfile
[main 136cbff] test
1 file changed, 3 insertions(+), 1 deletion(-)
(.pia-aws) ec2-user:~/environment/DevOps_Microservices (main) $ git push
Enter passphrase for key '/home/ec2-user/.ssh/id_rsa':
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 288 bytes | 144.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:theyoung/Containerization.git
e7b2cf4..136cbff main -> main
(.pia-aws) ec2-user:~/environment/DevOps_Microservices (main) $
git remote의 url을 ssh url로 변경해 줘야 한다.
ssh url은 상위 이미지를 확인하면 된다.
728x90
반응형
'Software활용' 카테고리의 다른 글
kubernetes install on ubuntus with Hyper-V (0) | 2021.03.04 |
---|---|
Kubernetes Deployments No resources (0) | 2021.03.01 |
Git branch 분리하기 (0) | 2021.03.01 |
tomcat install on centos (0) | 2020.03.27 |
Redis Config Explain (0) | 2020.03.27 |