2

How can I delete one of my devices from the "lists of known hosts (ECDSA)" after connecting to it with SSH on Sierra ?

2

Or just simply using ssh-keygen -R ip-address-or-hostname-of-your-device.

  • Thanks for your tip but doesn't it only regard keys ? I would like to delete all traces of the hosts in my known hosts file. – MFJC May 17 '17 at 10:02
  • What other traces would you like to remove? The file contains just the lines with public keys of the "devices". – Jakuje May 17 '17 at 10:06
  • Ok I used your technique to check it out, it worked thanks. – MFJC May 17 '17 at 10:11
  • However now it created a duplicate file called "known_hosts.old" that still contains the hostname, its IP and key, can I detele "known_hosts.old"? Also is it normal that such important modifications can be done from a normal user account with no sudo privileges ? Are these modifications system-wide ? Thanks ! – MFJC May 17 '17 at 10:12
  • 1) Yes. It is backup file in case it would do something unexpected so you can revert it. If it solved your problems, you can delete it. 2) Yes. It is file which is created by your user so it can be also modified by your user. 3) It is not system-wide. It is only for your user. – Jakuje May 17 '17 at 10:14
3

You can delete a device entry by navigating to ~/.ssh/known_hosts and remove the respective line:

  1. In the Finder hit cmdshiftG, enter ~/.ssh/ and hit Go. Open the file known_hosts with a text editor and remove the line with your device's host name or IP-address and the ecdsa key hint (e.g. ecdsa-sha2-nistp25).

  2. Open Terminal and enter nano ~/.ssh/known_hosts. Move the cursor to the respective line and hit ctrlK to remove the line. To save the modified file and exit nano hit ctrlO and ctrlX


The known_hosts file looks like this:

ip-address (or host name) key_hint key 

→ one line per ip-address/host!

Example:

host.example.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDWn...
192.168.0.7 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDEIb...
192.168.2.7 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDEIb...
host3 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDWn...
github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7...
host2.example.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHA...

Opening the file in an editor like TextEdit the lines are probably wrapped:

known_hosts file opened in TextEdit

To remove a host (in the example github.com), choose ip (or host name), key hint and key and delete it.

Editing ~/.ssh/known_hosts removes the host for the actual user only.

  • Thanks for your reply, if I only used SSH for that one connection to that one device I should see only that device in the file right ? I'm asking because even when I increase the width of the TextEdit window, the line still goes on 2 lines so I can't tell if it's one whole line returning to the 2nd line or if it's two lines. Or does every line is supposed to start with the IP of the device ? Thanks ! – MFJC May 13 '17 at 12:43
  • Surprisingly it seems I can find and open the file under my regular user account which is not admin, are the modifications only going to affect that user or also the admin user and other users on my Mac ? I think I used SSH as that normal user not the admin. – MFJC May 13 '17 at 12:47
  • Or just simply using ssh-keygen as intended. – Jakuje May 15 '17 at 10:58
  • Thanks for the tip but as mentioned in my previous comment just above, the line is very long and returns to the second line of the file. Should I delete both lines as they are one (a long crypto key maybe) or just the first one ? Thanks ! – MFJC May 17 '17 at 10:03
  • @Jakuje Thanks for the update of your answer with the answer to my question regarding the lines. In the end while I was waiting I tried Jakuje's solution and it worked but I can easily see how your answer would have solved it using the GUI instead. Thanks again ! Wish I could mark as answered both answers. – MFJC May 17 '17 at 11:19

You must log in to answer this question.

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