Created
April 7, 2024 05:25
-
-
Save AdrianAcala/2962c555ab3ff0066f9a095673c88a7b to your computer and use it in GitHub Desktop.
Removes all IPs from known_hosts except IPs that start with 192 or have an FQDN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while IFS= read -r line; do | |
if [[ $line =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[[:space:]] ]]; then | |
ip=$(echo "$line" | awk '{print $1}') | |
if [[ $ip =~ ^192\. ]]; then | |
echo "$line" | |
fi | |
else | |
echo "$line" | |
fi | |
done < ~/.ssh/known_hosts > ~/.ssh/known_hosts.new && mv ~/.ssh/known_hosts.new ~/.ssh/known_hosts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment