개발자 λ˜λŠ” μ‹œμŠ€ν…œμ„ μš΄μš©ν•˜λŠ” μ‚¬λžŒλ“€μ΄ μ„œλ²„ μ—”μ§€λ‹ˆμ–΄κ°€ κ΅¬μΆ•ν•œ 원격 ν˜ΈμŠ€νŠΈμ— μ ‘μ†ν•˜κΈ° μœ„ν•΄μ„œ SSH ν”„λ‘œν† μ½œμ„ μ‚¬μš©ν•œλ‹€. μš°λ¦¬κ°€ 컴퓨터에 λ‘œκ·ΈμΈν•˜λŠ” κ²ƒμ²˜λŸΌ κ°„λ‹¨ν•˜κ²Œ μ‚¬μš©μž 이름과 λΉ„λ°€λ²ˆν˜Έλ₯Ό μ‚¬μš©ν•˜κΈ°λ„ ν•˜λ©° κ³΅κ°œν‚€ 기반 인증으둜 λΉ„λ°€λ²ˆν˜Έλ₯Ό λŒ€μ²΄ν•˜κ±°λ‚˜ 2FA(OTP)λ₯Ό μΆ”κ°€μ μœΌλ‘œ μΈμ¦ν•˜μ—¬ λ³΄μ•ˆμ„ μ μš©ν•˜κΈ°λ„ ν•œλ‹€. SSH ν”„λ‘œν† μ½œμ„ μ‚¬μš©ν•˜λŠ” μ΄μœ μ—λŠ” TCP λ³΄μ•ˆ 채널을 μ—°κ²°ν•˜κ³  톡신 λ‚΄μš©μ— λŒ€ν•΄ μ•”ν˜Έν™”ν•˜μ—¬ νŒ¨ν‚·μ„ λ³΄ν˜Έν•˜κ³  μ•ˆμ „ν•˜κ²Œ μ„œλ²„μ— μ ‘μ†ν•˜μ—¬ 톡신할 수 μžˆλ„λ‘ κ΅¬μ„±ν•˜κΈ° μœ„ν•¨μ— μžˆλ‹€. 초보 개발자라면 이 글을 ν†΅ν•΄μ„œ SSH ν‚€νŽ˜μ–΄λ₯Ό λ°œκΈ‰ν•΄λ³΄κ³  μ•„λ§ˆμ‘΄ μ›Ή μ„œλΉ„μŠ€μ˜ EC2 μΈμŠ€ν„΄μŠ€ λ˜λŠ” κΉƒν—ˆλΈŒ μ €μž₯μ†Œμ— λ“±λ‘ν•˜μ—¬ 원격 ν˜ΈμŠ€νŠΈμ— μ—°κ²°ν•˜λŠ” 방법을 ν†΅ν•΄μ„œ SSH에 λŒ€ν•΄ 이해해보기λ₯Ό λ°”λž€λ‹€.

λ¨Όμ €, μ„œλ²„ μ—”μ§€λ‹ˆμ–΄κ°€ λ¦¬λˆ…μŠ€ μ„œλ²„ ν™˜κ²½μ„ μ€€λΉ„ν•˜κ³  μ œκ³΅ν•΄μ£ΌλŠ” κ²ƒμ²˜λŸΌ λ‚΄ 컴퓨터에 κ°€μƒμ˜ λ¦¬λˆ…μŠ€ ν™˜κ²½μ„ λ§Œλ“€μ–΄λ³Ό 수 μžˆλŠ”λ° μ•„λž˜μ˜ 두가지 방법 μ€‘μ—μ„œ OracleVM VirtualBox을 μ‚¬μš©ν•΄μ„œ λ¦¬λˆ…μŠ€ μ„œλ²„λ₯Ό μ€€λΉ„ν•˜μ˜€λ‹€.

sudo apt-get update
sudo apt-get install openssh-server
ssh -V
OpenSSH_8.9p1 Ubuntu-3, OpenSSL 3.0.2 15 Mar 2022

VirtualBox둜 μ€€λΉ„λœ μš°λΆ„νˆ¬ λ¦¬λˆ…μŠ€μ˜ μ£Όμ†ŒλŠ” 192.168.0.28 이닀.

λ‚΄ 컴퓨터에 μ„€μΉ˜λœ OpenSSH ν΄λΌμ΄μ–ΈνŠΈλ₯Ό μ‚¬μš©ν•΄μ„œ μœ„ μš°λΆ„νˆ¬ λ¦¬λˆ…μŠ€μ— 접속해보도둝 ν•˜μž.

PS C:\Users\Mambo> ssh ubuntu@192.168.0.28
ubuntu@192.168.0.28's password:
Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-47-generic x86_64)

μ‹€μ œ λ¦¬λˆ…μŠ€ μ„œλ²„ 그리고 인프라에 λ”°λΌμ„œ μ—¬λŸ¬κ°€μ§€ λ„€νŠΈμ›Œν¬ λ°©ν™”λ²½ 정책이 μžˆμ„ 수 μžˆμ§€λ§Œ μ§€κΈˆμ€ λ‚΄ 컴퓨터에 가상 ν™˜κ²½μœΌλ‘œ μš°λΆ„νˆ¬ λ¦¬λˆ…μŠ€λ₯Ό μ€€λΉ„ν–ˆκ³  μ–΄λ–€ 방화벽도 μ‘΄μž¬ν•˜μ§€ μ•ŠμœΌλ―€λ‘œ μ‚¬μš©μž 이름과 λΉ„λ°€λ²ˆν˜Έλ§ŒμœΌλ‘œ SSH ν”„λ‘œν† μ½œμ„ μ‚¬μš©ν•˜μ—¬ λ¦¬λˆ…μŠ€ μ„œλ²„μ— μ—°κ²°ν•  수 μžˆμ—ˆλ‹€.

SSH ν‚€ νŽ˜μ–΄

μ•„λ§ˆμ‘΄ μ›Ή μ„œλΉ„μŠ€μ˜ EC2 μΈμŠ€ν„΄μŠ€ λ˜λŠ” κΉƒν—ˆλΈŒ μ €μž₯μ†Œμ™€ 같은 μ„œλΉ„μŠ€μ—μ„œλŠ” SSH ν”„λ‘œν† μ½œμ„ μ‚¬μš©ν•΄μ„œ μ„œλ²„μ— μ—°κ²°ν•  λ•Œμ— μ‚¬μš©μž 이름과 λΉ„λ°€λ²ˆν˜Έλ₯Ό μ‚¬μš©ν•˜μ§€ μ•Šκ³  κ³΅κ°œν‚€ 기반의 ν‚€ νŽ˜μ–΄λΌλŠ” 것을 μ‚¬μš©ν•œλ‹€. λΉ„λ°€λ²ˆν˜Έ 인증보닀 κ³΅κ°œν‚€ 기반 인증을 κ΅¬μ„±ν•˜λŠ” μ΄μœ λŠ” λΉ„λ°€λ²ˆν˜Έ 인증 λ°©μ‹μ˜ κ²½μš°μ—λŠ” μ„œλ²„μ—μ„œ μ‚¬μš©λ˜λŠ” λΉ„λ°€λ²ˆν˜Έλ₯Ό μ™ΈλΆ€λ‘œ κ·ΈλŒ€λ‘œ λŒ€μΉ­ν‚€λ‘œμ¨ λ…ΈμΆœν•˜λŠ” 것이며 κ³΅κ°œν‚€ 기반 인증은 μ„œλ²„μ—μ„œ μ‹ λ’°ν•  수 μžˆλŠ” ν‚€λ₯Ό λ³΄μœ ν•œ ν΄λΌμ΄μ–ΈνŠΈκ°€ μ„œλ‘œ λ‹€λ₯Έ ν‚€λ₯Ό 가지고 있기 λ•Œλ¬Έμ΄λ‹€.

SSH ν‚€νŽ˜μ–΄κ°€ λ³΄μ•ˆμ μœΌλ‘œ μ™„λ²½ν•œ 것은 μ•„λ‹ˆλ―€λ‘œ SSH ν΄λΌμ΄μ–ΈνŠΈκ°€ λ³΄μœ ν•˜λŠ” λΉ„λ°€ν‚€κ°€ 제 3μžμ—κ²Œ νƒˆμ·¨λ˜μ§€ μ•Šλ„λ‘ 잘 κ΄€λ¦¬ν•΄μ•Όν•˜λŠ” 것은 ν•„μš”ν•˜λ‹€.

SSH ν‚€ νŽ˜μ–΄ μƒμ„±ν•˜κΈ°

μ•„λ§ˆμ‘΄ μ›Ή μ„œλΉ„μŠ€λ₯Ό μ΄μš©ν•˜λŠ” 개발자라면 μ›Ή μ½˜μ†”μ΄λ‚˜ AWS CLI의 create-key-pair λͺ…령을 μ‚¬μš©ν•΄μ„œ RSA λ˜λŠ” ED25519 기반의 ν‚€ νŽ˜μ–΄λ₯Ό κ°„λ‹¨ν•˜κ²Œ 생성할 수 μžˆλ‹€. κ·ΈλŸ¬λ‚˜, 일반적인 경우라면 μ–΄λ– ν•œ ν™˜κ²½μ— μ˜μ‘΄ν•˜μ§€ μ•Šκ³  OpenSSH에 ν¬ν•¨λœ ssh-keygen 도ꡬλ₯Ό μ‚¬μš©ν•˜λŠ” 방법에 λŒ€ν•΄μ„œ μ•Œμ•„μ•Όν•œλ‹€. μ•žμ„œ, μ€€λΉ„λœ μš°λΆ„νˆ¬ λ¦¬λˆ…μŠ€μ— μ‚¬μš©μž 이름과 λΉ„λ°€λ²ˆν˜Έλ₯Ό μ‚¬μš©ν•΄μ„œ μ ‘μ†ν•˜μ˜€μ„λ•Œ μœˆλ„μš°μ˜ OpenSSH ν΄λΌμ΄μ–ΈνŠΈλ₯Ό μ΄μš©ν•˜μ˜€λŠ”λ° μœˆλ„μš° 10의 선택적 κΈ°λŠ₯을 ν†΅ν•΄μ„œ κ°„λ‹¨ν•˜κ²Œ OpenSSH ν΄λΌμ΄μ–ΈνŠΈλ₯Ό μ„€μΉ˜ν•  수 있고 Git Bashλ₯Ό μ„€μΉ˜ν•΄λ„ ssh-keygen이 ν¬ν•¨λ˜μ–΄μžˆμœΌλ―€λ‘œ μžμ‹ μ΄ μ›ν•˜λŠ” 방식을 선택해보면 쒋을 것 κ°™λ‹€.

μœˆλ„μš° 10의 선택적 κΈ°λŠ₯을 ν†΅ν•΄μ„œ μ„€μΉ˜ν•œ OpenSSH ν΄λΌμ΄μ–ΈνŠΈ

# in Windows Terminal
PS C:\Users\Mambo\keypair> ssh -V
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5

# in Git Bash
$ ssh -V
OpenSSH_9.0p1, OpenSSL 1.1.1p  21 Jun 2022

OpenSSHλ₯Ό ν™•μΈν–ˆλ‹€λ©΄ Generating a new SSH key and adding it to the ssh-agentλ₯Ό μ°Έκ³ ν•΄μ„œ ssh-keygen으둜 SSH ν‚€νŽ˜μ–΄λ₯Ό μƒμ„±ν•˜λŠ” 방법에 λŒ€ν•΄μ„œ μ•Œμ•„λ³΄μž.

RSA ν‚€ νŽ˜μ–΄

PS C:\Users\Mambo\keypair> ssh-keygen -t rsa -b 4096 -m PEM -f win-mambo-rsa-4096.pem
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in win-mambo-rsa-4096.pem.
Your public key has been saved in win-mambo-rsa-4096.pem.pub.
The key fingerprint is:
SHA256:F3ECBEjeXszb6ccTJ2EWz9eaxvZoAg4f6F4rU0aDYJY mambo@DESKTOP-OJJ4TB3
The key's randomart image is:
+---[RSA 4096]----+
|   ....+o.o o    |
|   ...Eo   + +  .|
|    .o..+.. + o o|
|     . ..+o= o + |
|      . S.*.o B  |
|       . *o+ * o |
|        .o= = o .|
|       .o. o +   |
|        .o.      |
+----[SHA256]-----+

ED25519 ν‚€ νŽ˜μ–΄

PS C:\Users\Mambo\keypair> ssh-keygen -t ed25519 -m PEM -f win-mambo-ed25519.pem
Generating public/private ed25519 key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in win-mambo-ed25519.pem.
Your public key has been saved in win-mambo-ed25519.pem.pub.
The key fingerprint is:
SHA256:oad/A11tVJQFxRIDA63pozCFj/FsTCDh51hALNdFBVU mambo@DESKTOP-OJJ4TB3
The key's randomart image is:
+--[ED25519 256]--+
|   o+o o++++E.+BB|
|  ..+.o     ..oo.|
|   o..oo.  o o . |
|     =o.o.o . o  |
|    . oXSo . .   |
|      +oB +      |
|      .+ o .     |
|       .. o      |
|        .. .     |
+----[SHA256]-----+

λ¨Όμ €, RSA 기반의 ν‚€ νŽ˜μ–΄λ₯Ό λ§Œλ“€λ•ŒλŠ” 기본적으둜 2048 λΉ„νŠΈ μ΄μƒμœΌλ‘œ λ§Œλ“€μ–΄μ§€κ²Œ λ˜λŠ”λ° μ•„λ§ˆμ‘΄ μ›Ή μ„œλΉ„μŠ€λ‚˜ κΉƒν—ˆλΈŒ μ €μž₯μ†Œμ—μ„œλŠ” λͺ¨λ‘ 4096 λΉ„νŠΈλ₯Ό μ§€μ›ν•˜κ³  있으며 이λ₯Ό ꢌμž₯ν•˜λŠ” νŽΈμ΄λ‹€. 그런데, μ‹œμŠ€ν…œμ—μ„œ ED25519 방식을 μ§€μ›ν•œλ‹€λ©΄ ν‚€ 길이에 λ”°λ₯Έ λ³΄μ•ˆ 효율 상 ED25519λ₯Ό μ‚¬μš©ν•˜λŠ”κ²Œ 더 λ‚˜μ€ 선택이 될 수 μžˆλ‹€.

SSH κ³΅κ°œν‚€ λ“±λ‘ν•˜κΈ°

PS C:\Users\Mambo\keypair> scp .\window-mambo.pub ubuntu@192.168.0.28:/home/ubuntu/.ssh/
ubuntu@192.168.0.28's password:
window-mambo.pub                                                                      100%  104    51.6KB/s   00:00

# in ubuntu
ubuntu@ubuntu:~/.ssh$ cat window-mambo.pub >> authorized_keys
PS C:\Users\Mambo\keypair> ssh -i .\window-mambo.pem ubuntu@192.168.0.28
Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-47-generic x86_64

μ΄λ ‡κ²Œ ν•΄μ„œ SSH ν‚€ νŽ˜μ–΄λ₯Ό λ°œκΈ‰ν•˜κ³  가상 ν™˜κ²½μΈ μš°λΆ„νˆ¬ λ¦¬λˆ…μŠ€μ— ν‚€ νŽ˜μ–΄λ₯Ό λ“±λ‘ν•˜κ³  SSH둜 μ ‘μ†ν•΄λ³΄μ•˜λ‹€. μ„œλ²„ μ—”μ§€λ‹ˆμ–΄λŠ” μ΄λŸ¬ν•œ 과정을 거치게 λ˜λ©΄μ„œ μ΅œμ’…μ μœΌλ‘œ 개발자인 μš°λ¦¬μ—κ²Œ μ„œλ²„μ— 접속할 μ‚¬μš©μž 이름과 ν•¨κ»˜ λΉ„λ°€ν‚€λ₯Ό μ „λ‹¬ν•œ κ²ƒμž„μ„ μ•Œ 수 μžˆλ‹€.

SSH ν‚€ νŽ˜μ–΄ μ‹€μŠ΅

이제 μ•„λ§ˆμ‘΄ μ›Ή μ„œλΉ„μŠ€μ™€ κΉƒν—ˆλΈŒ μ €μž₯μ†Œ μ„œλΉ„μŠ€μ— SSH ν‚€νŽ˜μ–΄λ₯Ό λ“±λ‘ν•˜κ³  μ—°κ²°ν•˜λŠ” 것을 μ‹€μŠ΅ν•΄λ³΄λ©΄μ„œ λ‹€μ‹œ ν•œλ²ˆ 머리에 μˆ™μ§€ν•˜λ„λ‘ ν•΄λ³΄μž.

κΉƒν—ˆλΈŒ κ³΅κ°œν‚€ λ“±λ‘ν•˜κΈ°

λ¨Όμ €, μ‚¬λ‚΄μ—μ„œ μ‚¬μš©μ€‘μΈ 쑰직 κ³„μ •μœΌλ‘œ λ“±λ‘λ˜μ–΄μžˆλŠ” 프라이빗 κΉƒν—ˆλΈŒ λ¦¬νŒŒμ§€ν† λ¦¬λ₯Ό λ³΅μ‚¬ν•΄μ˜€κ±°λ‚˜ ν‘Έμ‹œν•΄μ•Όν•œλ‹€λ©΄ 쑰직에 μ†ν•œ λ‚΄ μ‚¬μš©μž 계정에 SSH ν‚€ νŽ˜μ–΄λ₯Ό λ“±λ‘ν•˜κ³  κΉƒν—ˆλΈŒ μ„œλ²„μ— 인증할 수 μžˆμ–΄μ•Ό ν•œλ‹€. μ‚¬μš©μž 계정 μ„€μ • > μ•‘μ„ΈμŠ€ > SSH and GPG Keys λ©”λ‰΄λ‘œ μ§„μž…ν•˜λ©΄ SSH ν‚€ νŽ˜μ–΄λ₯Ό 등둝할 수 μžˆλ„λ‘ μ œκ³΅ν•˜κ³  μžˆμœΌλ―€λ‘œ μ•žμ„œ λ§Œλ“€μ—ˆλ˜ ED25519 ν‚€ νŽ˜μ–΄λ₯Ό λ“±λ‘ν•˜κ³  κΉƒν—ˆλΈŒμ— 접속할 수 μžˆλŠ”μ§€ ν…ŒμŠ€νŠΈ ν•΄λ³΄μž.

κΉƒν—ˆλΈŒ μ„œλ²„μ— μš°λ¦¬κ°€ λ§Œλ“  ν‚€ νŽ˜μ–΄λ₯Ό λ“±λ‘ν•˜μ˜€μœΌλ―€λ‘œ λ‚΄ μ»΄ν“¨ν„°μ˜ OpenSSH ν΄λΌμ΄μ–ΈνŠΈλ‘œ κΉƒν—ˆλΈŒμ— μ—°κ²°ν•  수 μžˆλŠ”μ§€ ν™•μΈν•΄λ³΄μž. κΉƒν—ˆλΈŒμ—μ„œλŠ” μ•žμ„œ λ¦¬λˆ…μŠ€ μ„œλ²„μ— μ—°κ²°ν–ˆλ˜ 것 처럼 μ‰˜μ„ μ œκ³΅ν•˜μ§€λŠ” μ•Šμ§€λ§Œ 인증에 성곡할 수 μžˆλŠ”μ§€ 검증해볼 수 μžˆλ‹€.

PS C:\Users\Mambo\keypair> ssh -i win-mambo-ed25519.pem -T git@github.com
The authenticity of host 'github.com (15.164.81.167)' cannot be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,15.164.81.167' (ECDSA) to the list of known hosts.
Hi kdevkr! You've successfully authenticated, but GitHub does not provide shell access.

EC2 κ³΅κ°œν‚€ λ“±λ‘ν•˜κΈ°

μ•„λ§ˆμ‘΄ μ›Ή μ„œλΉ„μŠ€μ—μ„œ EC2 μΈμŠ€ν„΄μŠ€λ₯Ό μ‹€ν–‰ν•  λ•Œ ν‚€ νŽ˜μ–΄λ₯Ό μžλ™μœΌλ‘œ λ§Œλ“€μ–΄μ£ΌκΈ°λ„ ν•˜λŠ”λ° 이미 λ§Œλ“€μ–΄μ§„ SSH ν‚€ νŽ˜μ–΄λ₯Ό κ°€μ Έμ™€μ„œ λ“±λ‘ν•˜κ³  μ‚¬μš©ν•  수 μžˆλ„λ‘ μ§€μ›ν•˜κ³  μžˆλ‹€. λ‚΄ μ»΄ν“¨ν„°μ—μ„œ λ°œκΈ‰ν–ˆλ˜ κ³΅κ°œν‚€λ₯Ό κ°€μ Έμ™€μ„œ λ“±λ‘ν•œ ν›„ EC2 μΈμŠ€ν„΄μŠ€μΈ λ¦¬λˆ…μŠ€ μ„œλ²„μ— 접속할 수 μžˆλŠ”μ§€ ν™•μΈν•΄λ³΄μž.

PS C:\Users\Mambo\keypair> ssh -i win-mambo-ed25519.pem ec2-user@15.164.219.55
The authenticity of host '15.164.219.55 (15.164.219.55)' cannot be established.
ECDSA key fingerprint is SHA256:64Ca/STwUWZkN+ggo5jx6BCvwyhNRcCY5/xjk0SkSjU.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '15.164.219.55' (ECDSA) to the list of known hosts.

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/

[ec2-user@ip-10-0-2-243 ~]$ cat ~/.ssh/authorized_keys
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOy21gZ45To8FNf6hilxV51QqT9JCBjIpVKCRlup7m4D window-mambo

EC2 μΈμŠ€ν„΄μŠ€κ°€ 퍼블릭 μ„œλΈŒλ„·μ— μœ„μΉ˜ν•˜κ³  22번 ν¬νŠΈκ°€ ν—ˆμš©λ˜μ–΄μžˆλ‹€λ©΄ SSH ν‚€ νŽ˜μ–΄λ₯Ό μ‚¬μš©ν•˜μ—¬ EC2 μΈμŠ€ν„΄μŠ€μ— 접속할 수 μžˆλŠ”λ°, μΈν„°λ„·μ—μ„œ λ°”λ‘œ μ ‘κ·Όν•  수 μ—†λŠ” 프라이빗 μ„œλΈŒλ„·μ— μœ„μΉ˜ν•œ EC2 μΈμŠ€ν„΄μŠ€μ— SSM μ—μ΄μ „νŠΈλ₯Ό κ΅¬μ„±ν•œλ‹€λ©΄ μ•„λ§ˆμ‘΄ μ›Ή μ„œλΉ„μŠ€μ—μ„œ μ œκ³΅ν•˜λŠ” SSM μ—”λ“œν¬μΈνŠΈλ₯Ό μ‚¬μš©ν•΄μ„œ SSH 접속이 κ°€λŠ₯ν•˜λ„λ‘ λ§Œλ“€ 수 μžˆλ‹€.

νŠΈλŸ¬λΈ”μŠˆνŒ…

μ§€λ‚œ ED25519 글을 읽어본 뢄듀이라면 μœˆλ„μš° μ»΄ν“¨ν„°μ—μ„œ λ°œκΈ‰ν•œ ED25519 ν‚€ νŽ˜μ–΄λ₯Ό λ°œκΈ‰ν•˜κ³  μœˆλ„μš° ν™˜κ²½μ—μ„œ λΉ„λ°€ν‚€λ₯Ό μ‚¬μš©ν•΄μ„œ 인증을 μ‹œλ„ν•˜λ©΄ ν‚€ ν˜•μ‹μ΄ μ˜¬λ°”λ₯΄μ§€ μ•Šμ•„μ„œ μ‹€νŒ¨ν•˜λŠ” λ¬Έμ œκ°€ μžˆλ‹€λŠ” 것을 ν™•μΈν–ˆμ„ 것이닀. μ§€λ‚œλ²ˆ κΈ€μ—μ„œλŠ” λ‹¨μˆœνžˆ μ•ˆλ˜λŠ” 뢀뢄을 μ–ΈκΈ‰ν•˜κ³  λ§ˆλ¬΄λ¦¬ν•˜μ˜€μ§€λ§Œ 이 λ¬Έμ œμ— λŒ€ν•΄μ„œ μ™œ κ·ΈλŸ°κ²ƒμΈκ°€μ— λŒ€ν•΄ κΆκΈˆν•΄μ‘Œκ³  aws-cli/discussions/7074둜 κ΄€λ ¨ λ¬Έμ œμ— λŒ€ν•΄μ„œ μ§ˆλ¬Έμ„ ν†΅ν•΄μ„œ 원인을 찾게 λ˜μ—ˆλ‹€.

μœˆλ„μš° ν™˜κ²½μ—μ„œ AWS CLIλ₯Ό ν†΅ν•΄μ„œ ν‚€ νŽ˜μ–΄λ₯Ό λ°œκΈ‰ν•˜κ³ λ‚˜μ„œ λΉ„λ°€ν‚€ νŒŒμΌμ— λŒ€ν•΄μ„œ μ—λ””ν„°λ‘œ 열어보면 μœ„μ™€ 같이 UTF-16LE 인코딩 ν˜•μ‹κ³Ό CRLF κ°œν–‰ λ°©μ‹μœΌλ‘œ λ˜μ–΄μžˆλŠ” 것을 확인할 수 μžˆμ—ˆλ‹€. OpenSSH의 ssh-keygen으둜 λ§Œλ“€μ–΄μ§€λŠ” ν‚€νŽ˜μ–΄ νŒŒμΌμ„ μ‚΄νŽ΄λ³΄λ©΄ UTF-8κ³Ό LF둜 λ§Œλ“€μ–΄μ§€λŠ”λ° Git Bash에 ν¬ν•¨λ˜μ–΄μžˆλŠ” dos2unixλΌλŠ” 도ꡬλ₯Ό ν†΅ν•΄μ„œ UTF-16LE둜 λ˜μ–΄μžˆλŠ” 인코딩 ν˜•μ‹μ„ UTF-8둜 변경해보고 μ‹œλ„ν•΄λ³Έκ²°κ³Ό μ •μƒμ μœΌλ‘œ 접속을 μˆ˜ν–‰ν•  수 μžˆμ—ˆλ‹€.

$ dos2unix aws-mambo.pem
dos2unix: converting UTF-16LE file aws-mambo.pem to UTF-8 Unix format...
PS C:\Users\Mambo\keypair> ssh -i aws-mambo.pem ec2-user@3.34.188.47

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
[ec2-user@ip-10-0-2-42 ~]$

λ˜ν•œ, μœˆλ„μš° 터미널이 μ•„λ‹ˆλΌ Git Bashμ—μ„œ μ‹œλ„ν•΄λ³Έ κ²°κ³Ό λ‹€μŒκ³Ό 같이 λ‹€μ‹œν•œλ²ˆ ν‚€ ν˜•μ‹μ΄ μ˜¬λ°”λ₯΄μ§€ μ•Šλ‹€λŠ” λ©”μ‹œμ§€κ°€ λ°œμƒν–ˆλŠ”λ° μ΄λ²ˆμ—λŠ” CRLF둜 λ˜μ–΄μžˆλ˜ κ°œν–‰ ν˜•μ‹μ„ LF둜 λ³€κ²½ν•˜κ²Œλ˜λ©΄ μ„±κ³΅μ μœΌλ‘œ 접속할 수 μžˆμŒμ„ ν™•μΈν–ˆλ‹€.

$ ssh -i aws-mambo.pem ec2-user@3.34.188.47
Load key "aws-mambo.pem": invalid format
ec2-user@3.34.188.47: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
$ ssh -i aws-mambo.pem ec2-user@3.34.188.47

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
[ec2-user@ip-10-0-2-42 ~]$

μ‹€λ¬΄μ—μ„œ SSH ν‚€ νŽ˜μ–΄λ₯Ό μ „λ‹¬λ°›μ•˜λŠ”λ° SSH 접속이 λΆˆκ°€λŠ₯ν•˜λ‹€λ©΄ 전달받은 ν‚€ νŽ˜μ–΄ 파일의 인코딩 ν˜•μ‹κ³Ό κ°œν–‰ ν˜•μ‹μ„ μ‚΄νŽ΄λ³΄κ³  μœ„μ™€ 같이 λ³€κ²½ν•΄μ„œ μ‹œλ„ν•΄λ³΄κΈ°λ₯Ό μΆ”μ²œν•œλ‹€.

μ‹€λ¬΄μ—μ„œλŠ” 쑰직 ν˜Ήμ€ 인프라 ν™˜κ²½λ§ˆλ‹€ λ‹€μ–‘ν•œ λ°©μ‹μœΌλ‘œ μ„œλ²„μ— 접속할 수 μžˆλŠ” 방법을 μ œν•œν•˜λŠ”λ°μš”. 배슀천 호슀트둜 μš°μ„  μ ‘μ†ν•˜κ±°λ‚˜μ„œ 각 μ„œλ²„λ§ˆλ‹€ 정해진 μ‚¬μš©μž 이름과 λΉ„λ°€λ²ˆν˜Έλ₯Ό μ‚¬μš©ν•˜μ—¬ μ΄λ™ν•΄μ•Όν•˜κ±°λ‚˜ μ‹¬μ§€μ–΄λŠ” SSH ν‚€ νŽ˜μ–΄ 인증 뿐만 μ•„λ‹ˆλΌ OTPλ₯Ό ν†΅ν•œ 2FA 인증을 μš”κ΅¬ν•˜λ„λ‘ κ΅¬μ„±ν•˜κΈ°λ„ ν•©λ‹ˆλ‹€. μ €λŠ” μ„œλ²„ μ—”μ§€λ‹ˆμ–΄κ°€ μ•„λ‹ˆλ―€λ‘œ SSH μ—°κ²° μ‹œ 2FA을 κ΅¬μ„±ν•˜λŠ” 것은 λͺ¨λ₯΄κΈ°μ— 이 뢀뢄에 λŒ€ν•΄μ„œλŠ” λ³„λ„λ‘œ μ°Ύμ•„λ³΄μ•„μ•Όκ² μŠ΅λ‹ˆλ‹€.

μ°Έκ³