Tentando fazer o SSH no servidor e obtendo key_load_public: nenhum erro de arquivo ou diretório


43

Eu criei uma conexão ssh sem senha para o meu servidor remoto a partir do meu mac. Funcionou (!) E fechei o meu terminal, reabrei-o, tentei novamente e obtive o seguinte (nome de usuário, meu_ip não é real):

ssh -vvv username@my_ip
OpenSSH_7.2p2, LibreSSL 2.4.1
debug1: Reading configuration data /Users/Me/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: /etc/ssh/ssh_config line 53: Applying options for *
debug2: resolving "my_ip" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to my_ip [my_ip] port 22.
debug1: Connection established.
debug1: identity file /Users/Me/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Me/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Me/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Mes/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Me/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Me/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Me/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Me/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2
ssh_exchange_identification: read: Connection reset by peer

Quando chequei minha .sshpasta, id_rsaestava lá, mas nenhum dos outros estava. Pelo erro, parece que eu preciso criar esses arquivos de alguma forma, mas não tenho certeza de como fazê-lo.

Qualquer ajuda seria apreciada.


1
Existe algum problema real? Por exemplo, você realmente não está logando? Você poderia editar sua pergunta para incluir a saída de depuração completa, em vez da primeira parte?
Kenster #

Sim; me desculpe! Não consigo fazer login - e havia deixado a última (e talvez a mais importante?) Linha anterior.
Eric

Respostas:


51
debug1: key_load_public: No such file or directory

A linha acima não é um erro, mas apenas um log de depuração simples, informando que o sshcliente não pode encontrar uma chave pública separada (nomeada ~/.ssh/id_rsa.pub). Este arquivo não é necessário para se conectar ao servidor remoto, mas pode ser útil.

O erro real

ssh_exchange_identification: read: Connection reset by peer

aponta para erro na configuração do servidor. O servidor está em execução, mas falha ao aceitar a conexão SSH. Verifique o log do servidor para obter mais informações. Problemas semelhantes


Esse link foi muito útil. E, verifica-se que eu estava de fato na lista negra (eu tinha ssh'ed no meu servidor muitas vezes enquanto eu estava testando algo.)
Eric

1
Meu problema era que um host Bastion havia alterado o endereço IP e known_hostsestava incorreto no meu Mac ... Ele mostrava @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @... Ele mostra o número da linha por ~/.ssh/known_hosts:238. Portanto, removi essa linha, 238, neste caso, do arquivo known_hosts no meu Mac e tentei conectar-me novamente com êxito.
Marcello de Sales

3

Problema: incompatibilidade de IP do host bastião em ~/.ssh/known_hosts

Eu tinha o known_hostsarquivo antigo, pois o endereço IP do bastião foi alterado ...

$ ssh 10.82.49.24
ssh_exchange_identification: Connection closed by remote host

Não me deu nenhuma informação. Observar a saída detalhada leva à mesma coisa:

$ ssh -v 10.82.49.24
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/mdesales/.ssh/config
debug1: /Users/mdesales/.ssh/config line 1: Applying options for 10.82.*.*
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Executing proxy command: exec ssh -q -W 10.82.49.24:22 ec2-user@bastion-vpc-xxxxxx.config-yyyyyyy.com -i ~/.ssh/xxxconfig-xxxx.pem
debug1: key_load_public: No such file or directory
debug1: identity file ~/.ssh/xxxconfig-xxxx.pem
debug1: key_load_public: No such file or directory
debug1: identity file ~/.ssh/xxxconfig-xxxx.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: permanently_drop_suid: 1647059022
ssh_exchange_identification: Connection closed by remote host

Neste ponto, como é um proxy para outro host através do bastião, eu podia ver o bastião sendo um problema:

$ ssh ec2-user@bastion-vpc-xxxxxx.config-yyyyyyy.com -i ~/.ssh/xxxconfig-xxxx.pem
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:Z8X1UlIgQ94BKJ7NA/oQi7v0NL4IlFeO7Ou4j76Zphk.
Please contact your system administrator.
Add correct host key in /Users/mdesales/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/mdesales/.ssh/known_hosts:238
ECDSA host key for ec2-user@bastion-vpc-xxxxxx.config-yyyyyyy.com has changed and you have requested strict checking.
Host key verification failed.

Solução

A remoção da entrada na linha 238 resolveu o problema ... Eu poderia ssh no bastião e ssh nos hosts.

$ vim /Users/mdesales/.ssh/known_hosts

$ ssh ec2-user@bastion-vpc-xxxxxx.config-yyyyyyy.com -i ~/.ssh/xxxconfig-xxxx.pem
The authenticity of host 'ec2-user@bastion-vpc-xxxxxx.config-yyyyyyy.com (34.x.x.y)' can't be established.
ECDSA key fingerprint is SHA256:Z8X1UlIgQ94BKJ7NA/oQi7v0NL4IlFeO7Ou4j76Zphk.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ec2-user@bastion-vpc-xxxxxx.config-yyyyyyy.com -i ~/.ssh/xxxconfig-xxxx.pem,34.213.y.x' (ECDSA) to the list of known hosts.
********************************************************************************
This is a private computer system containing information that is proprietary
and confidential to the owner of the system.  Only individuals or entities
authorized by the owner of the system are allowed to access or use the system.
Any unauthorized access or use of the system or information is strictly
prohibited.

All violators will be prosecuted to the fullest extent permitted by law.
********************************************************************************
Last login: Wed Aug  2 20:35:55 2017 from 10.81.31.115
[ec2-user@ip-10-82-50-142 ~]$ 

1

Aconteceu comigo hoje.

Corrigido desconectando minha WLAN e reconectando. Sim, parece estúpido e estúpido, mas pelo menos em uma WLAN, isso aconteceu sem nenhuma boa razão.


0

Mesmo problema, basta postar a solução aqui

Remova seu IP do /etc/hosts.denyuso:

nano /etc/hosts.deny
Ao utilizar nosso site, você reconhece que leu e compreendeu nossa Política de Cookies e nossa Política de Privacidade.
Licensed under cc by-sa 3.0 with attribution required.