How To Search authorized_keys For Public Key And Remove It
772
Hello I am looking for assistance searching /root/.ssh/authorized_keys for a given public key (call it $pub_key) and removing it. Want to do this in bash script.
Would grep -v $pub_key /root/.ssh/authorized_keys > /tmp/authorized_keys.new work? You can compared to two files to verify the work. Given the long strings of random characters that comprise the keys, it's probably sufficient to do this using a substring of $pub_key.
Would
grep -v $pub_key /root/.ssh/authorized_keys > /tmp/authorized_keys.new
work? You can compared to two files to verify the work. Given the long strings of random characters that comprise the keys, it's probably sufficient to do this using a substring of $pub_key.Never forget the power of perl oneliners!
That will perform an in-place edit and remove the offending key.
Or, perhaps you have a really really long authorized_keys file and you want to process it in parallel with gnu parallel?
the possibilities are endless.
update: fixed typo that Ole pointed out. Thanks Ole!
Remove the space before
d
, it will work as you expect: