1. 개요
Tmax사 Anylink 제품을 설정 하던 중 이슈가 발생하였다.
Anylink 전문 연계 중 파일 업로드 관련을 SSH + SFTP으로 업/다운로드를 하는 서비스가 존재하여,
기존 비밀번호 기간 만료로 인해 OS AIX, LINUX 등 Pam 모듈 제한이 발생하였다.
임시 조치 → 서비스 정상화 확인 후 대안 방안을 고민하던 중 RSA Public, Private 인증 방식을 떠올라 적용하고자 한다.
2. 이슈
1) ssh-keygen 기본 모듈로 하면 안된다! (정상케이스는 하단 참조)
#잘못된 예시 -- OPEN SSH 로 생성된 RSA 인증서 파일은 정식 모듈이 아니다!
ssh-keygen -t rsa
$ cat /c/Users/YYH-G/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDhAbV3hpeTXoy0h2MjYnqtsMqzw9PhMOwszpWOk+GT9fr+QfOZbTuxRkmkbx0pcrPruDRYhgPCDTtz3sLqqnoGvD8sSESc+4v4HJqj+KIPmxAnIYw6nBK3PbNkI/pnR3/V/fIrkGW+zm8W0Zons82uHdXzvi4cfj/oZCC+vUSxeWW11qwe0wbyBB9oOmuqTcdIzYPu5NXyQQRDZyLptcG6Swi/es1OmV+T+Eb513jtxy2NnH/X8Fhv+E5SOvP1RtlpB+mRUw7w2fJC31DKgke4z8n/mzfKjRoc8dYTBiJTMifB0yzh6uWbKdiROcDv30UXf8Z3Ixqs4tnJJ5ppODzOYWzpfz++zAIhKLlO4/E+QZ6bhVRxrPTS65nvTJIk0Zc+HGTJG18nHywT0Am2zzeQ/EqEzPT2rr1zb9NbUBChZ1yxasWJc/1kCLo9m1kwNfQgJM2ky145FuJaPnTthJPqTLNyniYyAe3QsKNwRrwjiX9NPiE04LfImC3wvkfOTjE= YYH-G@YYH-G
$ cat /c/Users/YYH-G/.ssh/id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
NhAAAAAwE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wQDiluQuYYx/5qIX5GuGIrHc/iBALoBB/NfO
2pLWlDaE8ARTlL8y8W7cfAJzI0QmjMrhPwd2CsHWCcpMMh1yQAMYB6imeItoInYT4hWiHx
E8VeUk7Z8SxmOtblhPd1+UlzzxBHVt0T+6ZBdtU3wU4zEaiUs5jVtyK4E3uRBOYfwD/aeN
elXozI3/6zLxVXANkZCxs1CaqVSg4rnmVRHJSN1+QF/JKT3B6bUF0c51KsNr8VjMVo6Xbe
rwW+Ujk4kMhTsAAAALWVlILUdAWVlILUc=
-----END OPENSSH PRIVATE KEY-----
2) ssh-keygen 정상적인 사용법
ssh-keygen -m PEM \
-t rsa \
-b 4096 \
-C "계정@호스트" \
-f /c/Users/YYH-G/.ssh/test_rsa
$ cat /c/Users/YYH-G/.ssh/test_rsa
-----BEGIN RSA PRIVATE KEY-----
MIIJKAIBAAKCAgEAotLyQv+urFCo85tzhJOxzCi9D39qaxyTfV2nKBnMfyeZmYb7
TLaw3rvKWkGBjy3dFHZFbhlvS7+suqqkn4mqaT53v18r8GZ4gp/FglaGPqTpumCm
x+Lrr4zZy2ISW0d33GV2z6KE1tF6f9UWbWBh2UFxuU98BwJL2hH4YldA7LbfDtLu
Oka+p4ei0ii3EX8MldGuVaBaSM3yyLhIlrCk4uBdWnAqahlO8jlaTssDIzR5W/og
9zUOQB6CAjr7mt1AkblLV3dpZ9AgPxBVCfNN57NyMCPGK9i1lVQCkJyWW4Scp/Nx
T4dXWX1IJrXhJNx4xlrBfiEeX4Vbx1Sfu+8nxcUvy/i35uZxLwYOqxAsMaJWcTt4
zLwd96Rz7K+cyyj3rgDttqxIdppz5k8Sf4pAxI3ImjHev3hzcBJSfcHTvFTsprSq
rJlD0nBla68kqDsQQDluO1PbYt6csiVPvSVr6z7v986faAdftZMGFWenESEfqsDt
k1NZQRdNsZ9PZuZvESR4imV92azonoa1Q1FBo5IDr9DXGUFlAC7pQIOKYc5jMcwA
UJOilG8D67mXo5Z++AEDM8JZZU/JUwoQnjatkJ15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cr4dpbDH2XWRK0/RBfO0YMIWGyu9ebcd4eUSV+56CK0vrT7gM18rOz5z4CVE+n+8NBq2+Uh/4x9w== yyh@localhost
3. 매우 중요한 사항
1) Java + SSH 모듈 Jsch 모듈 관련
꽤 많은 상용 서비스들이 Jcraft 사의 Jsch SSH 라이브러리를 이용한다.
다만 해당 라이브러리의 경우 Public , Private Key 사용시 범용이 아닌 이상 지원하지 아니 한다.
대표적으로 OpenSSH (ssh-keygen) 기본 생성 방식 or RSA SSH (ssh-keygen -m pem) 방식의 차이이다.
2) OpenSSH 로 만들어진 인증서를 사용 하는 경우 발생하는 이슈는 대표적으로 한가지 있다.
/*
(X) -----BEGIN OPENSSH PRIVATE KEY----- // 방식으로 만들어진 KEY는 절대 사용 불가이다.
(O) -----BEGIN RSA PRIVATE KEY----- // 으로만 가능하다. PEM 방식
*/
Caused by: com.jcraft.jsch.JSchException: invalid privatekey: [B@24a1f
at com.jcraft.jsch.KeyPair.load(KeyPair.java:902)
at com.jcraft.jsch.KeyPair.load(KeyPair.java:543)
at com.jcraft.jsch.IdentityFile.newInstance(IdentityFile.java:40)
at com.jcraft.jsch.JSch.addIdentity(JSch.java:393)
at com.jcraft.jsch.JSch.addIdentity(JSch.java:353)
at com.jcabi.ssh.SSH.session(SSH.java:261)
'Programming > 스프링.유틸' 카테고리의 다른 글
AWS AMI 환경에서 Selenium 크롬 드라이버 이슈 해결 방법 (1) | 2024.09.22 |
---|---|
[JAVA] TempFileCleanJob - 임시 파일 정리 작업 구현 (0) | 2024.07.14 |
[자바][JAVA][파일업로드]자바 파일업로드 기초 소스 (초급자용) (0) | 2022.03.20 |
Image Test 및 부정 클릭 방지 테스트. (0) | 2021.11.18 |
[Spring F/W 유틸] Dynamic Get Bean Object (0) | 2021.09.07 |