github을 원격지로 repo로 사용할 경우 기본적으로 https로 접속하게되며 매번 ID/PWD을 입력 해야한다. ssh 접속으로 변경하면 ID/PWD 없이 가능하여 편리하다.
> ssh-keygen -t ed25519 -C "igotoo@gmail.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/igotoo/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/igotoo/.ssh/id_ed25519
Your public key has been saved in /home/igotoo/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:c62zCE0hCHtamHWXcgSvvXsdfsdsb91ekvcbcYnLOuhh/GcNc igotoo@gmail.com
The key's randomart image is:
+--[ED25519 256]--+
| . . .. o.o.. |
| * o. . o . |
| + +..o. . |
| + +..... . |
| . . S+.... E |
| o o=oo.. o|
| . ..+++=..o|
| . oo*. *..|
drwxr-xr-x 14 igotoo igotoo 4096 May 23 19:08 ..
-rw-r--r-- 1 igotoo igotoo 141 May 23 18:01 config
-r-------- 1 igotoo igotoo 1675 May 23 17:30 gblg3_id_rsa
-rw------- 1 igotoo igotoo 411 May 23 19:08 id_ed25519
-rw-r--r-- 1 igotoo igotoo 98 May 23 19:08 id_ed25519.pub
-r-------- 1 igotoo igotoo 3354 May 21 18:34 id_rsa.bak
-r-------- 1 igotoo igotoo 1679 May 21 18:35 kdrvstg_id_rsa
-rw-r--r-- 1 igotoo igotoo 3108 May 23 17:28 known_hosts
> eval "$(ssh-agent -s)"
Agent pid 611
> ssh-add ~/.ssh/id_ed25519
Identity added: /home/igotoo/.ssh/id_ed25519 (igotoo@gmail.com)
ssh-agent를 eval로 실행 시키는 이유
eval는 명령
명령 치환 결과로 shell 에서 실행 가능한 명령문이 나온다면 그 명령은 기본적으로 실행이 가능합니다. 하지만 명령문이 조금 복잡해져서 파이프나 redirections, quotes 등이 사용된다면 이제는 그 명령문은 실행할 수 없게 됩니다. 왜냐하면 명령문에서 사용되는 shell 키워드, 메타문자들, quotes 등은 확장과 치환 이전에 해석이 완료되기 때문입니다. 따라서 이와 같은 경우에도 실행이 가능하게 해주는 명령이 eval 명령입니다. eval 은 인수로 주어지는 스트링을 한번 evaluation 한 후에 결과를 다시 명령문으로 실행합니다.
다음과 같이 ssh-agent를 실행하는 경우 환경변수를 셋팅하고 백그라운드로 실행되어야 하는데 eval를 사용하는 경우 명령문에서 먼저 해석이 되어 환경 변수가 셋팅 되지 않는다.
> env | grep -i SSH
SSH_AUTH_SOCK=
SSH_AGENT_PID=
> ssh-agent -s
SSH_AUTH_SOCK=/tmp/ssh-4sIsqE1flEg0/agent.1456; export SSH_AUTH_SOCK;
SSH_AGENT_PID=1457; export SSH_AGENT_PID;
echo Agent pid 1457;
> env | grep -i SSH
SSH_AUTH_SOCK=
SSH_AGENT_PID=
> eval "$(ssh-agent -s)"
Agent pid 1469
> env | grep -i SSH
SSH_AUTH_SOCK=/tmp/ssh-5vZqJr5zfN7B/agent.1468
SSH_AGENT_PID=1469
> git push
Username for 'https://github.com': igotoo@gmail.com
Password for 'https://igotoo@gmail.com@github.com':
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/igotoo/igotoo.github.io.git/'
> git remote remove origin
> git remote add origin git@github.com:igotoo/igotoo.github.io.git
> git push
fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin main
> git push --set-upstream origin main
The authenticity of host 'github.com (15.164.81.167)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,15.164.81.167' (RSA) to the list of known hosts.
Enumerating objects: 17, done.
Counting objects: 100% (17/17), done.
Delta compression using up to 8 threads
Compressing objects: 100% (14/14), done.
Writing objects: 100% (14/14), 3.24 MiB | 2.01 MiB/s, done.
Total 14 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:igotoo/igotoo.github.io.git
feb878a..83dabb5 main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
> git push
Warning: Permanently added the RSA host key for IP address '52.78.231.108' to the list of known hosts.
Everything up-to-date
/mnt/d/Blog/mediator main
> echo "github login test2" >> test.txt
> git add test.txt
> git commit -m "github login test2 /w ssh"
[main 346a1d4] github login test2 /w ssh
1 file changed, 1 insertion(+)
> ps -ef|grep ssh-agent
igotoo 886 271 0 19:21 pts/2 00:00:00 man ssh-agent
> cat ~/.ssh/config
#Host github.com
# User git
# IdentityFile ~/.ssh/id_ed25519
Host gblg3.igotoo.pw
User igotoo
Port 22222
IdentityFile ~/.ssh/gblg3_id_rsa
> git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 280 bytes | 17.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:igotoo/igotoo.github.io.git
f1dce52..346a1d4 main -> main