Hugo, Git password 에서 SSH key 인증으로 변경
- 사용중인 Hugo blog, git password 인증 방식을 ssh key 인증으로 변경하기
- 기본 암호 인증방식은 곧 사용하지 못한다는 메일을 받고 진행 (Update: Mar 25, 2021)
환경 구성
- OS: CentOS 7 (on Oracle cloud VM)
- Git: v2.8
1. SSH key 생성
USER1@SVR1 ~]$ cd /home/USER1/.ssh/ ; ls -al
total 20
-rw-------. 1 USER1 USER1 398 Mar 15 17:46 authorized_keys
USER1@SVR1 .ssh]$ ssh-keygen -t rsa -b 4096 -C "{MY-GIThub@E-MAIL.com}"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/USER1/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/USER1/.ssh/id_rsa.
Your public key has been saved in /home/USER1/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:k0dw+Hx+ve7DrWjQyH8/d/Bc0vruawvfuT0x/v6azl4 {MY-GIThub@E-MAIL.com}
The key's randomart image is:
+---[RSA 4096]----+
| . . |
| = . . |
| . o o |
| o o |
| . oo . S |
| + .o ... . . |
| o .oooo o +E|
| o.oo= o*..+++|
| ....oo*o=Bo*XB|
+----[SHA256]-----+
USER1@SVR1 ~]$
USER1@SVR1 ~]$ ls -al /home/USER1/.ssh/
total 20
-rw-------. 1 USER1 USER1 398 Mar 15 17:46 authorized_keys
-rw------- 1 USER1 USER1 3243 Mar 24 13:48 id_rsa
-rw-r--r-- 1 USER1 USER1 743 Mar 24 13:48 id_rsa.pub
USER1@SVR1 ~]$ eval "$(ssh-agent -s)"
Agent pid 24423
USER1@SVR1 ~]$ ssh-add /home/USER1/.ssh/id_rsa
Identity added: /home/USER1/.ssh/id_rsa (/home/USER1/.ssh/id_rsa)
2. Github에서 생성된 key 등록
;id_rsa.pub 암호화 키를 복사해서 Github 계정 설정에서 적용
github.com → Settings → SSH and GPG keys → NEW SSH Key
USER1@SVR1 ~]$ cat /home/USER1/.ssh/id_rsa.pub
ssh-rsa AAAAB8NzaClyc2EAAAADAQABAAABAQBYQmm (...생략...)
3. Hugo 블로그에 git 재설정
USER1@SVR1 ~]$ cd ~/Hugo/Blog
USER1@SVR1 Blog]$ git remote show
origin
USER1@SVR1 ~]$ cd ~/Hugo/Blog/public
USER1@SVR1 public]$ git remote show
origin
USER1@SVR1 Blog]$ git remote remove origin
USER1@SVR1 ~]$ cd ./public
USER1@SVR1 public]$ git remote remove origin
USER1@SVR1 Blog]$ git remote add origin git@github.com:0l0000/BlogHugoContents.git
USER1@SVR1 Blog]$ rm -rf ./public/
USER1@SVR1 Blog]$ git submodule add -b master git@github.com:0l000/0l0000.github.io.git public
Cloning into 'public'...
remote: Enumerating objects: 1626, done.
remote: Counting objects: 100% (1626/1626), done.
remote: Compressing objects: 100% (672/672), done.
remote: Total 8853 (delta 1017), reused 1409 (delta 805), pack-reused 7227
Receiving objects: 100% (8853/8853), 3.15 MiB | 1.03 MiB/s, done.
Resolving deltas: 100% (5132/5132), done.
Checking connectivity... done.
4. Hugo 블로그 git 재설정 중 이슈들
USER1@SVR1 Blog]$ git submodule add -b master git@github.com:0l000/0l0000.github.io.git public
'public' already exists in the index
USER1@SVR1 Blog]$ rm -rf /home/USER1/Hugo/Blog/public/
USER1@SVR1 Blog]$ git submodule add -b master git@github.com:0l000/0l0000.github.io.git public
A git directory for 'public' is found locally with remote(s):
If you want to reuse this local git directory instead of cloning again from git@github.com:0l000/0l0000.github.io.git
use the '--force' option. If the local git directory is not the correct repo or you are unsure what this means choose another name with the '--name' option.
USER1@SVR1 Blog]$ cd /home/USER1/Hugo/Blog
USER1@SVR1 Blog]$ git ls-files --stage |grep public
160000 96d334513c6221278f4337234cfcdfe3ea07d01c 0 public
USER1@SVR1 Blog]$ git rm --cached public
rm 'public'
USER1@SVR1 Blog]$ rm -rf /home/USER1/Hugo/Blog/.gitmodules #./public만 남아있어 삭제
USER1@SVR1 Blog]$ rm -rf /home/USER1/Hugo/Blog/.git/modules/public
USER1@SVR1 public]$ git add .
fatal: Unable to create '/home/USER1/Hugo/Blog/.git/index.lock': File exists.
USER1@SVR1 Blog]$ rm -rf /home/USER1/Hugo/Blog/.git/index.lock
USER1@SVR1 public]$ git add .
git: pathspec.c:317: prefix_pathspec: Assertion 'item->nowildcard_len <= item->len && item->prefix <= item->len' failed.
Aborted (core dumped)
USER1@SVR1 Blog]$ git ls-files --stage |grep public
160000 881a2be2556ab336aadc57a25d256a5e87e60a8e 0 public/tags
(...생략...)
USER1@SVR1 Blog]$ git rm -r --cached public
(...생략...)
delete mode 100644 public/tags/index.html
delete mode 100644 public/tags/index.xml
delete mode 100644 public/tags/page/1/index.html