How to modify known_hosts entries?

To modify entries in the known_hosts file, you can follow these steps:

  1. Open the known_hosts file: This file is typically located in the ~/.ssh/ directory. You can open it using a text editor. For example, using nano:

    nano ~/.ssh/known_hosts
    
  2. Locate the entry: Each line in the known_hosts file corresponds to a host. You can search for the specific host entry you want to modify.

  3. Edit the entry: You can either modify the existing line or delete it and add a new entry. If you want to delete a line, simply remove it. To add a new entry, you can use the format:

    hostname,ip_address key_type key
    

    For example:

    example.com,192.168.1.1 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAr...
    
  4. Save the changes: After making your modifications, save the file and exit the editor. In nano, you can do this by pressing CTRL + X, then Y to confirm changes, and Enter to exit.

  5. Verify the changes: You can verify that the changes were applied by using the ssh command to connect to the host and check for any warnings or errors.

Alternatively, you can use the ssh-keygen command to remove a specific entry without manually editing the file:

ssh-keygen -R hostname

Replace hostname with the actual host name or IP address you want to remove. This command will automatically remove the corresponding entry from the known_hosts file.

0 Comments

no data
Be the first to share your comment!