-2

I try to add my host to known host via terminal:

ssh-keyscan -H 195.118.254.45 >> ~/.ssh/known_hosts

But when I open my known hosts file with text edit, then it is still empty. Nothing was added.

peace_love
  • 6,229
  • 11
  • 69
  • 157
  • do you get any errors? this looks like something you would need to `sudo` to be able to do it... did you try with it? – blurfus Sep 08 '22 at 05:41
  • or you could just edit the know_hosts file manually as well (i.e. using `vim`, `vi`, `nano`, etc) – blurfus Sep 08 '22 at 05:42
  • @blurfus no error message, actually no message. Yes, I tried with sudo, too – peace_love Sep 08 '22 at 06:01
  • @blurfus How do I do it manually. Can I just copy the key fingerprint to the first line of the know hosts file? – peace_love Sep 08 '22 at 06:04
  • I try `ssh-keygen -R myhost.de` and I get the message `Host myhost.de not found in /Users/coding/.ssh/known_hosts`. What is the correct way to add myhost.de manually to the file? – peace_love Sep 08 '22 at 06:11
  • I tried `sudo ssh-keyscan -H 195.118.254.45 >> ~/.ssh/known_hosts` and also `sudo ssh-keyscan -H myhost.de >> ~/.ssh/known_hosts`. No reaction – peace_love Sep 08 '22 at 06:14
  • @blurfus I manually tried to add in the first line of the known_host file `195.118.254.45 SHA234:B1-nistp256 AAAAE2VjZHNhLXNoYTItb POVVQF/CzuAeQNv4fZVf2pLxpGHle15zkpxOosckequUDxoq` But now I get the error message `~/.ssh/known_hosts:1: invalid line` and `~/.ssh/known_hosts is not a valid known_hosts file.` so this is not working – peace_love Sep 08 '22 at 06:21
  • the command, as above, should work - perhaps use `-v` flag for verbose output? https://linuxhint.com/ssh-keyscan-ubuntu/ and see if you get more details – blurfus Sep 08 '22 at 06:34
  • to do it manually, have a look at the existing file and add a new line with the IP and the hash that gets returned (there might be other details that I can't think of) it's late here for me. For the invalid line error - make sure you have a new line at the end? – blurfus Sep 08 '22 at 06:35
  • 1
    peace: the correct format for a known_hosts line is: IPaddr-or-hash (your addr is valid), keytype-name (your SHA234:B1-nistp256 is gargage; the only valid keytype using p256 is ecdsa-sha256-nistp256), and ONE base64 blob (you have two; the first could be the _beginning_ of a valid blob for ecdsa-sha256-nistp256, but the second is not valid as posted). @blurfus: known_hosts can contain a hash INSTEAD of IPaddr, but NOT with one; it is addr-or-hash type keyblob, where the keyblob is emphatically not a hash of any kind at all ever. – dave_thompson_085 Sep 08 '22 at 06:36
  • @dave_thompson_085 Thank you, I do not understand everything. The only information I have is the hostname and the key fingerprints for ECDSA, RSA or Ed1234 – peace_love Sep 08 '22 at 06:41
  • @blurfus I tried `ssh-keyscan -v 195.118.254.45 >> ~/.ssh/known_hosts`. but no error message – peace_love Sep 08 '22 at 06:42
  • 1
    @blurfus I found a working solution: `ssh-keyscan -H -p 2222 -t ecdsa 195.118.254.45 >> ~/.ssh/known_hosts` Looks like the reason was the wrong port – peace_love Sep 08 '22 at 06:47

1 Answers1

1

The working solution for me was:

ssh-keyscan -H -p 2222 -t ecdsa 195.118.254.45 >> ~/.ssh/known_hosts

I had to define the correct port

peace_love
  • 6,229
  • 11
  • 69
  • 157