-2
I'm trying to connect to a new Ubuntu server. I was using the hardware of this server previously (with Desktop Ubuntu) before installing Ubuntu server. Do you know what can be happening?

    Bernardos-MacBook-Pro:~ bernardo$ ssh [email protected]
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @    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:4cTDTZMivYKNPugdQQlwGDKcV6FvnSTsY7jAf0hW7Q0.
    Please contact your system administrator.
    Add correct host key in /Users/bernardo/.ssh/known_hosts to get rid of this message.
    Offending ECDSA key in /Users/bernardo/.ssh/known_hosts:28
    ECDSA host key for 192.168.1.43 has changed and you have requested strict checking.
    Host key verification failed.

    Bernardos-MacBook-Pro:~ bernardo$ ssh-keygen -R 192.168.1.123
    Host 192.168.1.123 not found in /Users/bernardo/.ssh/known_hosts

    Bernardos-MacBook-Pro:~ bernardo$ sed -i '28d' ~/.ssh/known_hosts
    sed: 1: "/Users/bernardo/.ssh/kn ...": undefined label     'ernardo/.ssh/known_hosts'

after manually removing line 28

        Bernardos-MacBook-Pro:~ bernardo$ ssh [email protected]
        The authenticity of host '192.168.1.43 (192.168.1.43)' can't be established.
        ECDSA key fingerprint is SHA256:4cTDTZMivYKNPugdQQlwGDKcV6FvnSTsY7jAf0hW7Q0.

        Are you sure you want to continue connecting (yes/no)? yes

        Warning: Permanently added '192.168.1.43' (ECDSA) to the list of known hosts.

        Permission denied (publickey).

3 Answers 3

2

Installing sshd will automatically install a host key. When connecting to a host, the client will check whether it already has a key for the host you're trying to connect to. If it doesn't, it will ask you whether it is safe to connect to it. If it does, and it is the same as before, it won't ask any questions. But if it already has a key and it is different, it knows it is not connecting to the same OS installation it was connecting to before, and it assumes something is wrong. In this case, you reinstalled the OS without bothering to preserve and reinstall the previous host key, but your SSH client doesn't know that, someone else might be trying to impersonate as your host instead.

To get rid of this error, remove the old host key for this host from your

~/.ssh/known_hosts

As to why you can't remove that line with the sed command, I go with @user1700494's theory; use man sed to see what your sed supports.

5
  • giving 'Permission denied (publickey).' now
    – biotech
    Feb 11, 2016 at 12:30
  • You must reinstall your private key there. Feb 11, 2016 at 12:30
  • how can I do that?
    – biotech
    Feb 11, 2016 at 12:32
  • If you didn't do it the first time, I'm not going to tell you. Feb 11, 2016 at 12:32
  • Please, I just what to connect to my server.
    – biotech
    Feb 11, 2016 at 12:41
1

I don't use OS X but i know that OS X sed is not GNU sed. I guess that your sed doesn't understand -i key. You need either remove entry on line 28 manually in /Users/bernardo/.ssh/known_hosts or install gnu-sed

0
Please contact your system administrator.
Add correct host key in /Users/bernardo/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/bernardo/.ssh/known_hosts:28

You did that manually and got:

Permission denied (publickey)

Sounds like you need to either enable password based logins on the server, or add your public key to the authorized_users file on the server.

Not the answer you're looking for? Browse other questions tagged .