젠킨스 ssh로 ec2 연결중 BapPublisherException 예외..

정민영·2022년 5월 23일
3
post-thumbnail

별거아닌 내용이긴한데 혹시나 저처럼 고통받으시는 분에게 도움이 됐으면 해서 게시합니다!

프로젝트 배포 자동화를 구현하면서 오랜만에 젠킨스를 사용하게 되었습니다.
예전에도 사용해봐서 그렇게 무리 없을거라.....고 생각했는데......
빌드후 jar파일을 ec2에 던져야 하는데 젠킨스 시스템 설정후 pubilsh over ssh 설정후 'test configuration' 을해보면...

jenkins.plugins.publish_over.BapPublisherException: Failed to connect and initialize SSH connection. Message: [Failed to connect session for config [server__name]. Message [Auth fail]]

이런 에러가 나왔다.
분명 설정도 잘됐고 pem키도 넣어보고 rsa 공개키/개인키도 직접 만들어 설정해보고 젠킨스 pubilc over ssh플러그인이 문제인가해서 낮은 버전플러그인도 올려보고... 여러걸 해봤지만 해결이 되지않았고 너무 안되서 travis로 해야하나... 생각하던순간 ec2의 ubuntu 버전문제일수도 있다는 생각이 들어 ec2 ubuntu 버전을 "18.04로" 다시 생성해서 해봤더니.. 성공! 했습니다.
많은 문제는 버전에서 나올수 있다고 다시한번느끼며....2틀간의 삽질을 마무리하게 되었습니다. 하ㅏ하하하.. 삽질덕에 젠킨스랑 조금더 친해진 계기였습니다. 다만 다른분들을 고통받지 마시고 빨리 해결하시길..!

3개의 댓글

comment-user-thumbnail
2022년 8월 30일

https://github.com/jenkinsci/publish-over-ssh-plugin/issues/247

Hello,

We had the same problem and could not understand why a manual ssh connection from the jenkins machine works, but with the publish-over-ssh it doesn't. The key was a RSA 2048 key, and it worked perfectly before upgrading the machines from 18.04 to 22.04 (both the host, jenkins, and the remote machine where jenkins deploys).

We finally checked out the auth.log on the remote machine and it logged this error when Jenkins was trying to connect:

Jun 13 10:35:15 ip-XXX-XX-XX-XX sshd[3207]: userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]
Jun 13 10:35:15 ip-XXX-XX-XX-XX sshd[3207]: error: Received disconnect from XX.XX.XX.XX port 54588:3: com.jcraft.jsch.JSchException: Auth fail [preauth]
Jun 13 10:35:15 ip-XXX-XX-XX-XX sshd[3207]: Disconnected from authenticating user ubuntu XX.XX.XX.XX port 54588 [preauth]
Turns out, new openssh versions have ssh-rsa key types disabled by default. This was advised 2 years ago.
https://security.stackexchange.com/questions/226131/openssh-declares-ssh-rsa-deprecated-what-do-i-do-next

We guess the plugin is forcing sha-rsa instead of rsa-sha2-256/512. The local ssh client does have this in mind, thus the local ssh client is able to connect while the plugin not.

Temporally, we have added PubkeyAcceptedKeyTypes=+ssh-rsa to the remote server's sshd_config file to allow deployments.

Hope it helps if someone has the same problem.

답글 달기
comment-user-thumbnail
2022년 11월 25일

이거 pubilc over ssh플러그인이 SHA2 방식으로 접속을 안하고 SHA1 방식으로 접속시켜서 그런 것 같습니다. 아마도 높은 버전의 Ubuntu(혹은 OpenSSH)는 SHA1 방식을 허용하지 않아서 접속이 안되는 것이죠
https://superuser.com/questions/1390593/how-to-generate-ssh-rsa-key-instead-of-rsa-sha2-512

우분투 기준 /etc/ssh/sshd_config 에 다음 두줄을 추가하시고

PubkeyAuthentication yes
PubkeyAcceptedKeyTypes +ssh-rsa

sshd 서비스 재시작 하니까 문제가 해결되었습니다

sudo service sshd restart
1개의 답글