When you are trying to connect to a server via SSH. You can get the errors below:
- host key verification failed ssh
- ssh known_hosts error
- ssh host key verification failed fix
This error is caused by:
- The server has been reinstalled or upgraded, which may have generated a new host key or changed the host key format or algorithm.
- The server has rotated its host key, which is a good security practice to prevent the host key from being compromised or leaked.
- The network configuration of the server has changed, such as the IP address or the hostname.
- The known_hosts file on the client has been altered or corrupted, which may have deleted or modified the host key entry for the server.
Instead of modifying the known_hosts file. I created a small script which update the key for you.
It will take the ip and the port number of the server and update the old key to the new host key.
.
βββ LICENSE
βββ update-ssh.sh
- Clone the this repo main branch to your desktop.
- Open the folder and use this command to make the .sh exec.
chmod +x kill-port.sh - Link this folder to your .zshrc. This is mainly located in ~/.zshrc
- Use nano or vim to edit .zshrc
- Add the line to your .zshrc :
export PATH="$PATH:{folder}/update-ssh" - Replace {folder} with the correct path to this project
Once setup, write source .zshrc to apply the new changes
On your terminal, you can use it like below
update-ssh.sh -p {port} -i {ip}
Replace {port} and {ip} with the ssh IP and port number.
It will output if the script found the IP and port in known_hosts and updates it. The original content will save in known_hosts.old
Contributions are welcome! Here's how you can help:
- Fork the repository
- Clone your fork:
git clone https://github.com/shumatics/update-ssh.git - Create a new branch:
git checkout -b feature/your-feature - Commit your changes:
git commit -am 'Add some feature' - Push to your branch:
git push origin feature/your-feature - Open a pull request
Please ensure your code follows the project's style guidelines and includes tests where applicable.
This project is licensed under the LICENSE License.
This README was generated with β€οΈ by ReadmeBuddy