Skip to content

Instantly share code, notes, and snippets.

@cmer
Last active August 12, 2019 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmer/ae91fc7e97ad3e7933df9ff56a08563b to your computer and use it in GitHub Desktop.
Save cmer/ae91fc7e97ad3e7933df9ff56a08563b to your computer and use it in GitHub Desktop.
Script to remove last attempted SSH host from ~/.ssh/known_hosts
#!/usr/bin/env ruby
host = ARGV[0].to_s
if host == ""
history_output = `cat ~/.bash_history | grep "^ssh\s" | tail -1`
host = history_output.sub(/^ssh\s/i, '').split("@").last.split(" ").first
end
puts `ssh-keygen -R #{host}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment