> ## Content Index
> Fetch the complete content index at: https://developerinsider.co/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to remove known ssh host?
- URL: https://developerinsider.co/how-to-remove-known-ssh-host/
- Published: 2024-10-25T08:55:19.000Z
- Updated: 2024-10-25T09:04:41.000Z
- Author: Vineet Choudhary
- Tags: Tips, Linux, macOS, SSH, known_hosts

There are multiple option to remove a known ssh host from the `known_hosts` file.

## 1\. Use the ssh-keygen command

This is the easiest and safest method to remove the known ssh host form `known_hosts` file.

Run the following command by replacing the `<hostname_or_ip>` with the actual hostname or IP address of the ssh host -

```sh
ssh-keygen -R <hostname_or_ip>

```

For example:

```sh
ssh-keygen -R 172.16.10.10

```

or

```sh
ssh-keygen -R developerinsider.co

```

This will remove the host's entry from the `~/.ssh/known_hosts` file and also generate `~/.ssh/known_hosts.old` file with all the previous changes in case you want to revert the changes.

## 2\. Manually edit the known\_hosts file

First, create a backup of your `known_hosts` file in case you need to revert any changes. Use the following command to copy the current `known_hosts` file to `known_hosts.bak` \-

```ssh
sudo cp ~/.ssh/known_hosts ~/.ssh/known_hosts.bak

```

Now, open the `known_hosts` file in your favourite editior

```sh
nano ~/.ssh/known_hosts

```

![](https://cdn.developerinsider.co/images/linux/ssh/known-hosts-file.webp)  
Search for the host by its hostname or IP address and delete the corresponding line. After that, save your changes.

## 3\. Remove all known hosts

To remove all known hosts, you can delete the `known_hosts` file. Run the following command to delete `known_hosts` file.

```
sudo rm ~/.ssh/known_hosts

```

When you access a new host via SSH, this file will be recreated automatically.