SSH 공개 키가 서버로 전송되지 않습니다.

SSH 공개 키가 서버로 전송되지 않습니다.

나는 몇 시간 동안 이 문제로 어려움을 겪었으므로 도움을 주시면 대단히 감사하겠습니다 ...

나는 2개의 서버를 가지고 있고 sshOSX의 공개 키를 사용하여 전혀 문제 없이 두 서버 모두에 연결할 수 있으므로 확신합니다 sshd_config.

두 서버를 동기화 하도록 cron 작업을 구성하려고 하는데 공개 키를 사용하여 서버 B(백업)를 서버 A에 연결 rsync해야 합니다 .ssh

내 공개 키를 찾을 수 없는 이유를 평생 알 수 없습니다. 공개 키는 위치가 있고 ~/.ssh/(예: /root/.ssh) A와 B에 대한 모든 파일 권한이 정확합니다.

출력은 다음과 같습니다.

debug2: we did not send a packet, disable method
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug3: no such identity: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug3: no such identity: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug3: no such identity: /root/.ssh/id_dsa
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password

또한 존재하지 않는 개인 키를 찾고 있다는 점에 유의하세요.

drwx------. 2 root root 4096 May 25 10:15 .
dr-xr-x---. 4 root root 4096 May 24 18:52 ..
-rw-------. 1 root root  403 May 25 01:37 authorized_keys
-rw-------. 1 root root    0 May 25 01:41 config
-rw-------. 1 root root 1675 May 25 02:35 id_rsa_tm1
-rw-------. 1 root root  405 May 25 02:35 id_rsa_tm1.pub
-rw-------. 1 root root  395 May 25 02:36 known_hosts

답변1

대상 호스트의 잘못된 Authorized_keys 파일은 ssh가 "우리는 패킷을 보내지 않았습니다" 메시지를 출력하고 pubkey 인증을 사용하는 대신 비밀번호를 요청하는 또 다른 이유입니다.

debug1: Next authentication method: publickey
debug1: Offering RSA public key: ~/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug2: we did not send a packet, disable method

이 특별한 경우의 문제는 .ssh/authorized_keys대상 호스트에 붙여넣은 공개 키 데이터에 첫 번째 문자가 누락되었다는 것입니다.

sh-rsa AAAA...

해결책은 간단합니다. 누락된 "s"를 추가하는 것입니다.

ssh-rsa AAAA...

그래서:-

debug1: Next authentication method: publickey
debug1: Offering RSA public key: ~/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 279
...
debug1: Authentication succeeded (publickey).

답변2

SSH 매뉴얼 페이지를 살펴보십시오.

   -i identity_file
          Selects a file from which the identity (private key) for public
          key authentication is read.  The default is ~/.ssh/identity for
          protocol   version   1,   and  ~/.ssh/id_dsa,  ~/.ssh/id_ecdsa,
          ~/.ssh/id_ed25519 and ~/.ssh/id_rsa  for  protocol  version  2.
          Identity files may also be specified on a per-host basis in the
          configuration file.  It is possible to have multiple -i options
          (and  multiple  identities  specified  in configuration files).

또는 ssh_config 매뉴얼 페이지:

   IdentityFile
          Specifies a file from which the user's DSA, ECDSA,  ED25519  or
          RSA   authentication   identity   is   read.   The  default  is
          ~/.ssh/identity for  protocol  version  1,  and  ~/.ssh/id_dsa,
          ~/.ssh/id_ecdsa, ~/.ssh/id_ed25519 and ~/.ssh/id_rsa for proto‐
          col version 2.  Additionally, any identities represented by the
          authentication  agent  will  be  used for authentication unless
          IdentitiesOnly is set.

키를 지정하지 않으면 일부 특수 파일 이름이 시도되는 것을 볼 수 있습니다. 이는 로그 출력에도 표시되는 파일입니다.

다른 이름의 파일에서 키를 사용하려면 다음 세 가지 옵션이 있습니다.

  • 위의 옵션을 사용하여 파일을 명시적으로 지정합니다 -i.
  • 위의 옵션을 사용하여 IdentityFile클라이언트 구성에서 이 파일을 구성합니다 .
  • 에이전트에 키를 추가하는 데 사용합니다 ssh-add.

대화형 세션의 경우 상담원이 가장 유연합니다. 이 옵션은 아마도 cron 작업에 대한 -i가장 간단한 옵션일 것입니다 .

답변3

개인/공개 키 쌍이 일치하지 않는 경우에도 질문의 오류 메시지 문자열이 발생할 수 있습니다.지역 측에서. 아니요, 전혀 말이 안 됩니다. 하지만 무슨 일이 일어나고 있는지 알아내려고 오랜 시간을 보냈을 뿐입니다.

  • .ssh/mykey.pub원격 시스템 A가 에 복사 되었습니다 .ssh/authorized_keys.
  • 로컬 시스템 B에는 .ssh/mykey시스템 A의 공개 키와 일치하는 올바른 개인 키가 있지만 .ssh/mykey.pub대체 키의 이전 버전일 수 있는 일치하지 않는 파일도 있습니다.

B에서 A()로의 SSH는 문제의 메시지와 함께 실패합니다. 특히 ssh -i mykey ASSH 클라이언트에서 열면 다음과 같은 내용이 표시됩니다.-vv

개인 키를 사용해 보세요: .ssh/mykey
패킷을 보내지 않습니다. 방법을 비활성화합니다.

실제 키를 시도하는 대신 이름이 일치하는 로컬 공개 키 파일을 사용하여 작동 가능한지 확인한 다음 일치하지 않으면 실제로 아무 작업도 수행하지 않기 때문에 이는 거짓말입니다. 양쪽의 디버그 정보는 실제로 문제가 무엇인지 암시하지 않습니다.

답변4

ssh가 찾는 기본 파일 이름은 id_rsa및 입니다 id_rsa.pub.

다른 파일 이름을 사용하려면 다음에서 지정해야 합니다.ssh_config( IdentityFile설정 사용) 또는 SSH를 통해명령줄 범위 -i.

관련 정보