OpenSSL 라이브러리λ₯Ό 톡해 SSH 접속을 μœ„ν•œ ν‚€ νŽ˜μ–΄λ₯Ό λ°œκΈ‰ν•˜λŠ” κ²½μš°μ— 기본적으둜 RSA ν˜•μ‹μ˜ ν‚€ νŽ˜μ–΄κ°€ μƒμ„±λ˜μ–΄λ„ μ‹€μ œλ‘œλŠ” OPENSSH PRIVATE KEY둜 μ €μž₯되게 λœλ‹€. RSA PRIVATE KEY둜 μ €μž₯되기 μœ„ν•΄μ„œλŠ” -m μ˜΅μ…˜μœΌλ‘œ PEM을 지정해야 ν•œλ‹€.

# ----- OPENSSH PRIVATE KEY -----
ssh-keygen -t rsa -b 2048 -C "mambo" -N ""

# ----- RSA PRIVATE KEY -----
ssh-keygen -t rsa -b 2048 -m PEM -C "mambo" -N ""

일본 κ³ κ°μœΌλ‘œλΆ€ν„° 자체적으둜 κ΅¬μΆ•ν•œ μ„œλ²„μ— μ ‘μ†ν•˜κΈ° μœ„ν•œ 계정과 κ°œμΈν‚€ PEM νŒŒμΌμ„ λ°›μ•„λ³΄λ‹ˆ OPENSSH ν˜•μ‹μœΌλ‘œ μ €μž₯λ˜μ–΄μžˆμŒμ„ ν™•μΈν•˜μ˜€λ‹€. κ·ΈλŸ¬λ‚˜, SecureCRTλ₯Ό μ‚¬μš©ν•΄μ„œ μ„œλ²„μ— 처음으둜 μ—°κ²°ν•˜λ €κ³  ν–ˆμ„λ•Œ ν‚€ ν˜•μ‹μ΄ μ˜¬λ°”λ₯΄μ§€ μ•Šλ‹€λŠ” 였λ₯˜κ°€ λ°œμƒν•˜λ©° 접속에 μ‹€νŒ¨ν•˜μ˜€λ‹€.

-----BEGIN RSA PRIVATE KEY-----
[KEY CONTENT]
-----END RSA PRIVATE KEY-----

OPENSSH PRIVATE KEY둜 μ €μž₯λ˜μ–΄μžˆλŠ” 것을 RSA PRIVATE KEY둜 λ³€κ²½ν•˜κ³  μ‹œλ„ν•΄λ³΄λ‹ˆ μ •μƒμ μœΌλ‘œ 연결이 λ˜μ—ˆμœΌλ©° μžμ„Έν•œ 원인은 λͺ¨λ₯΄κ² μœΌλ‚˜ 2FA 인증을 μ„€μ •ν•˜κ³  λ‚˜μ„œλŠ” OPENSSH PRIVATE KEY둜 μ €μž₯λ˜μ–΄μžˆλŠ” PEM νŒŒμΌλ‘œλ„ 연결이 μ •μƒμ μœΌλ‘œ 연결을 ν•  수 μžˆλŠ” 상황이 λ˜μ—ˆλ‹€.

OpenSSH κ°œμΈν‚€λ₯Ό RSA κ°œμΈν‚€λ‘œ λ³€ν™˜

μ•„λ¬΄νŠΌ, RSA PEM ν˜•μ‹μœΌλ‘œ λ‹€μ‹œ λ§Œλ“€μ–΄λ‹¬λΌκ³  μš”μ²­ν•˜κΈ°μ—λŠ” μ‹œκ°„μ΄ 많이 μ†Œμš”λ  수 μžˆμœΌλ―€λ‘œ OPENSSH ν˜•μ‹μœΌλ‘œ λ˜μ–΄μžˆλŠ” RSA κ°œμΈν‚€λ₯Ό RSA PEM ν˜•μ‹μœΌλ‘œ λ³€ν™˜ν•΄λ³΄λ„λ‘ ν•˜μž.

ssh-keygen -t rsa -b 2048 -C "mambo" -N "" -f openssh.pem

# cat ~/.ssh/id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn
NhAAAAAwEAAQAAAQEAw4o9aOfBCkCzsuz3hMJT/v058pMki16Ft56tim4r5mJRbBd0EQPJ
3gm1FiJmp0fqrnJo+H3o4hBH0LlCbeXiXHloPnTi1JZTSzWat1ItcBG+xezx8BdmtKqdTy
PWfYL9ujLse5AAXkvVHhYHJ7koV72X9whH94Tci4zAEHRypKbuz+9lj5P94u1n/nYAt2PT
JmdP/Y+62qFiSGhKEh/Jed5TVvIrabOi+qcHQ0VmcXkTGiOTXLTmHMbce26dqsGRRb4YPf
1alXECX28b8QpbarlXHPeGJyQ5d8dxEhsOz60LDoUEy/ytn0g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k3UT2j
wDKS0IFNM6UX67CKSdYK/YFLAv3gtPEgrZ43ec1W6zlHUWmusAAACBANWFKfE3Ky1ubomZ
IovLa0XUs2h9rSUMDX3Su+Es/0x+qHP0bq2JKWTzVWoa0NgfnPAVJo/Fd8NVhIMs1od6iB
O3Kgz7A2Esg5sOtkK06nwSYMcfXMyuf+7fj0v0nBtjVH6EdOrU0muH4vvtxiYcw2N4cI+5
Fnns05+DCtL4o9kzAAAABW1hbWJvAQIDBAU=
-----END OPENSSH PRIVATE KEY-----

OPENSSH PRIVATE KEY둜 μ €μž₯λ˜μ–΄μžˆμŒμ„ ν™•μΈν•˜μ˜€μœΌλ‹ˆ μ•„λž˜μ˜ λͺ…령어듀을 μ‹€ν–‰ν•˜μ—¬ λ³€ν™˜λ˜λŠ”μ§€ 확인해보면 λœλ‹€.

# [1] OpenSSH
sudo ssh-keygen -p -m PEM -f openssh.pem

# [2] OpenSSL
openssl rsa -in openssh.pem -outform pem > openssh-rsa.pem

# [3] Putty
puttygen openssh.pem -O private-openssh -o openssh-rsa.pem

[1] OpenSSH

Windows Terminal
ssh-keygen -p -m PEM -f openssh.pem Failed to load key openssh.pem: invalid format

첫번째 OpenSSH λͺ…λ Ήμ–΄λ₯Ό μ΄μš©ν•˜λŠ” 방법은 가상 ν™˜κ²½μ— μ‹€ν–‰ν•œ μš°λΆ„νˆ¬ λ¦¬λˆ…μŠ€μ—μ„œλŠ” μ •μƒμ μœΌλ‘œ λ³€ν™˜λœ λ°˜λ©΄μ— μœˆλ„μš° ν„°λ―Έλ„μ—μ„œλŠ” μ•Œ 수 μ—†λŠ” ν˜•μ‹μ΄λΌλŠ” 였λ₯˜ λ©”μ‹œμ§€μ™€ ν•¨κ»˜ μ‹€νŒ¨ν•˜μ˜€λ‹€.

[2] OpenSSL πŸ’₯

openssl rsa -in openssh.pem -outform pem > openssh-rsa.pem

unable to load Private Key
140038194394432:error:0909006C:PEM routines:get_name:no start line:../crypto/pem/pem_lib.c:745:Expecting: ANY PRIVATE KEY

λ‘λ²ˆμ§Έ OpenSSL 라이브러리λ₯Ό μ΄μš©ν•˜λŠ” 방법은 ChatGTPμ—μ„œ μ•Œλ €μ€€ 것인데 OpenSSHλŠ” OpenSSL 라이브러리λ₯Ό ν™œμš©ν•˜κΈ°λŠ” ν•˜λ‚˜ OpenSSH ν”„λ‘œκ·Έλž¨μ—μ„œ μΈμ‹ν•˜λŠ” ν˜•μ‹μ΄λ―€λ‘œ λ³€ν™˜ν•˜λŠ” κ³Όμ •μ—μ„œ 였λ₯˜κ°€ λ°œμƒν•˜μ˜€λ‹€.

[3] Putty πŸ€

# [Mac] brew install putty
# [Ubuntu] apt install putty-tools
puttygen openssh.pem -O private-openssh -o openssh-rsa.pem

μ„Έλ²ˆμ§Έ 방법은 PuTTYgen을 μ΄μš©ν•˜λŠ” κ²ƒμœΌλ‘œ μœˆλ„μš° ν™˜κ²½μ—μ„œλŠ” μ»€λ§¨λ“œλΌμΈ μ˜΅μ…˜μ„ μΈμ‹ν•˜μ§€ λͺ»ν•œ κ΄€κ³„λ‘œ PuTTYgen(PuTTY Key Generator)을 μ‹€ν–‰ν•œ ν›„ Conversions λ©”λ‰΄μ˜ Import Key둜 뢈러온 ν›„ Export OpenSSH Key둜 μ €μž₯ν•˜λ©΄ RSA PRIVATE KEY둜 λ³€ν™˜ν•  수 μžˆμ—ˆμœΌλ©° μš°λΆ„νˆ¬ λ¦¬λˆ…μŠ€μ—μ„œλŠ” μ»€λ§¨λ“œλΌμΈμœΌλ‘œ 별닀λ₯Έ λ¬Έμ œμ—†μ΄ λ³€ν™˜ν•  수 μžˆλ‹€.

Conversions > Import Key

Conversions > Export OpenSSH Key

κ°œμΈμ μœΌλ‘œλŠ” 였래된 λ‚΄μš©μ΄μ§€λ§Œ ν•œλ²ˆ ν•˜κ³ λ‚˜μ„œλŠ” 더이상 닀루지 μ•ŠλŠ” 정보이기에 μžŠμ–΄λ²„λ¦΄ 것 κ°™μ•„ 기둝으둜 λ‚¨κΈ°κ³ μž κ³΅μœ ν•œλ‹€.