[Ubuntu] Certbot을 이용한 인증서 발급하기

[Ubuntu] Certbot을 이용한 인증서 발급하기

노션에서 보기

이채현

snapd 설치하기 (snapd 없는 경우)

최신 버전의 우분투에는 snapd가 설치되어있는 것으로 알고 있음

1
2
3
4
# apt # snap
# Ubuntu
sudo apt install snapd
sudo reboot

certbot 설치하기 (snap)

1
2
3
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

cloudflare plugin 설치하기

1
2
3
# dns  cloudflare
sudo snap set certbot trust-plugin-with-root=ok
sudo snap install certbot-dns-cloudflare

cloudflare api token 넣기

1
2
3
4
5
6
mkdir -p ~/.secrets/certbot
vi ~/.secrets/certbot/cloudflare.ini
----------------------------------
# Cloudflare API token used by Certbot
dns_cloudflare_api_token = IdgrE2pGEQxdq43kQPJ8*****************
chmod 600 ~/.secrets/certbot/cloudflare.ini

자신의 도메인 인증서 등록하기

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#
# *.4084.live
sudo certbot certonly --dns-cloudflare \\
--dns-cloudflare-credentials ~/.secrets/certbot/cloudflare.ini \\
-d *.4084.live

-----------------
ubuntu@dev-project-app:~$ sudo certbot certonly --dns-cloudflare \\
> --dns-cloudflare-credentials ~/.secrets/certbot/cloudflare.ini \\
> -d *.4084.live
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
<https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf>. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Account registered.
Requesting a certificate for *.4084.live
Waiting 10 seconds for DNS changes to propagate

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/4084.live/fullchain.pem
Key is saved at: /etc/letsencrypt/live/4084.live/privkey.pem
This certificate expires on 2022-02-26.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
* Donating to ISRG / Let's Encrypt: <https://letsencrypt.org/donate>
* Donating to EFF: <https://eff.org/donate-le>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

생성된 인증서 경로 /etc/letsencrypt/live/4084.live/fullchain.pem /etc/letsencrypt/live/4084.live/privkey.pem

인증서 갱신하기

1
2
3
4
5
#     (--dry-run)
sudo certbot renew --dry-run

#(xx )
sudo certbot renew

crontab을 이용하여 주기적으로 갱신

(매주 일요일 2시 1분에 실행)

1
2
3
4
crontab -e
-----------
# cert renewal
1 2 * * 0 sudo /usr/bin/certbot renew

참고링크


[Ubuntu] EC2 Ubuntu에 접속 후 초기 셋팅

[Ubuntu] EC2 Ubuntu에 접속 후 초기 셋팅

노션에서 보기

이채현

인스턴스를 생성할 때 키페어 생성하여 위치확인하기

키 페어 저장

다운로드 한 키페어를 ~/.ssh 폴더 안에 위치시키고 권한을 600으로 변경한다

1
2
cp ~/Downloads/{keypair-name.pem} ~/.ssh/AWS
chmod 600 {keypair-name.pem}

접속

1
ssh -i ./{keypair-name.pem} ubuntu@{public ipv4 주소}

로그인 후

패키지 업데이트

1
2
sudo apt update
sudo apt upgrade

hostname 변경

1
2
sudo hostnamectl set-hostname {원하는 이름}
# 재접속

타임존 변경

1
sudo timedatectl set-timezone Asia/Seoul

개인PC에서 간단히 접속하기

ssh명령어를 이용하여 접속할 때에는 인증키의 위치를 계정명, 주소를 같이 입력해줘야하는 번거로움이 있다.

이를 개인pc의 인증서를 등록하여 인증서없이 바로 로그인해보자

id_rsa 키 생성하기 (개인-Mac)

1
2
cd ~/.ssh
ssh-keygen

이후 ~/.ssh 폴더 내부에 생성 된 id_rsa(private) id_rsa.pub(public) 두개의 키를 확인할 수 있다.
이 중 id_rsa.pub의 내용을 복사한다.

authorized_keys 수정하기 (원격-Ubuntu)

1
2
vim ~/.ssh/authorized_keys
위에서 복사한 id_rsa.pub 내용을 붙여넣고 저장한다.