Advertisement
c0psrul3

ssh_config and sshd_config

Dec 30th, 2015
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. ssh_config & sshd_config :: Examples and notes on Configuration settings
  2. ===========================================================================
  3.  
  4.  
  5. To import a target's ssh-pubkey
  6. -------------------------------
  7. ssh-keygen -R [hostname]
  8. ssh-keygen -R [ip_address]
  9. ssh-keygen -R [hostname],[ip_address]
  10. ssh-keyscan -H [hostname],[ip_address] >> ~/.ssh/known_hosts
  11. ssh-keyscan -H [ip_address] >> ~/.ssh/known_hosts
  12. ssh-keyscan -H [hostname] >> ~/.ssh/known_hosts
  13.  
  14.  
  15. To remove (#6, line 6) from 'known_hosts' file (using `sed`)
  16. ------------------------------------------------------------
  17. #> sed -i '6d' ~/.ssh/known_hosts
  18.  
  19.  
  20. To remove (#6, line 6) from 'known_hosts' file (using `perl`)
  21. -------------------------------------------------------------
  22. #> perl -pi -e 's/\Q$_// if ($. == 6);' ~/.ssh/known_hosts
  23.  
  24.  
  25.  
  26. The below will do the trick to add a host, ONLY if it has not yet been added. It is also not concurrency safe; you must not execute the snippet on the same origin machine more than once at the same time, as the tmp_hosts file can get clobbered, ultimately leading to the known_hosts file becoming bloated... [[http://serverfault.com/questions/132970/can-i-automatically-add-a-new-host-to-known-hosts]]
  27. ---
  28. $> ssh-keyscan -t rsa,dsa HOST 2>&1 | sort -u - ~/.ssh/known_hosts > ~/.ssh/tmp_hosts
  29. mv ~/.ssh/tmp_hosts ~/.ssh/known_hosts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement