TheKoguryo's 기술 블로그

 Version 2024.04.01

Bastion Service 문제해결

세션 접속용 SSH command 실행시 접속 오류 - Permission denied (publickey)
  • 현상: Bastion 서비스 세션 생성후, SSH command로 접속시 아래와 같이 Permission denied (publickey) 오류 발생함.

    • 세션 생성시 사용한 SSH Key는 기존 Compute 인스턴스 생성시 사용시 연결 오류 발생하지 않음 => SSH Key 문제는 아닌 거 같은데..

    • 세션 생성시 “Generate SSH key pair"를 통해 OCI 콘솔에서 생성한 키를 사용해도 아래 오류 발생함 => SSH Key 문제는 아닌 거 같은데..

    $ ssh -i key -N -L 2022:10.0.0.47:22 -p 22 ocid1.bastionsession.oc1.ap-chuncheon-1.amaaaaaavsea7yiakgcncs7ick6c43y2xrzldehca3man7kykx4otskplqwa@host.bastion.ap-chuncheon-1.oci.oraclecloud.com
    ocid1.bastionsession.oc1.ap-chuncheon-1.amaaaaaavsea7yiakgcncs7ick6c43y2xrzldehca3man7kykx4otskplqwa@host.bastion.ap-chuncheon-1.oci.oraclecloud.com: Permission denied (publickey).
    
  • 원인:

    OpenSSH 8.8 릴리즈 정보를 보면 아래와 같이 SHA-1을 사용하는 RSA 서명을 비활성화하였다는 문구가 있습니다.

    OpenSSH 8.8 was released on 2021-09-26. It is available from the
    mirrors listed at https://www.openssh.com/.
    
    ...
    
    Potentially-incompatible changes
    ================================
    
    This release disables RSA signatures using the SHA-1 hash algorithm
    by default. This change has been made as the SHA-1 hash algorithm is
    cryptographically broken, and it is possible to create chosen-prefix
    hash collisions for <USD$50K [1]
    
    For most users, this change should be invisible and there is
    no need to replace ssh-rsa keys. OpenSSH has supported RFC8332
    RSA/SHA-256/512 signatures since release 7.2 and existing ssh-rsa keys
    will automatically use the stronger algorithm where possible.
    
    Incompatibility is more likely when connecting to older SSH
    implementations that have not been upgraded or have not closely tracked
    improvements in the SSH protocol. For these cases, it may be necessary
    to selectively re-enable RSA/SHA1 to allow connection and/or user
    authentication via the HostkeyAlgorithms and PubkeyAcceptedAlgorithms
    options. For example, the following stanza in ~/.ssh/config will enable
    RSA/SHA1 for host and user authentication for a single destination host:
    
        Host old-host
            HostkeyAlgorithms +ssh-rsa
            PubkeyAcceptedAlgorithms +ssh-rsa
    
    We recommend enabling RSA/SHA1 only as a stopgap measure until legacy
    implementations can be upgraded or reconfigured with another key type
    (such as ECDSA or Ed25519).
    
    [1] "SHA-1 is a Shambles: First Chosen-Prefix Collision on SHA-1 and
        Application to the PGP Web of Trust" Leurent,         
    

    일반적인 환경에서는 별다른 오류가 발생하지 않았는데, macOS에서 환경에서 업데이트를 잘 해서 그런지 아래와 같이 클라이언트의 버전이 9.4인 상태에서 OCI Bastion Service를 통해 세션을 연결할 때 위와 같은 오류가 발생하였습니다.

    • 노트북에 설치된 설치 버전 확인
    $ ssh -V
    OpenSSH_9.4p1, LibreSSL 3.3.6
    
  • 해결책

    OpenSSH 8.8 릴리즈 노트에서 설명되어 있는 것처럼, ~/.ssh/config 파일의 내용에 아래 설정을 추가합니다.

    Host *
        HostkeyAlgorithms +ssh-rsa
        PubkeyAcceptedAlgorithms +ssh-rsa
    
    • 설정후 다시 연결해 보면, 오류없이 연결되는 것을 알 수 있습니다.
    $ ssh -i key -N -L 2022:10.0.0.47:22 -p 22 ocid1.bastionsession.oc1.ap-chuncheon-1.amaaaaaavsea7yiakgcncs7ick6c43y2xrzldehca3man7kykx4otskplqwa@host.bastion.ap-chuncheon-1.oci.oraclecloud.com
    
  • 참고



이 글은 개인으로서, 개인의 시간을 할애하여 작성된 글입니다. 글의 내용에 오류가 있을 수 있으며, 글 속의 의견은 개인적인 의견입니다.

Last updated on 9 Nov 2023