Như Ignatio đề nghị điều này có thể được thực hiện với grep -v.
Dưới đây là một ví dụ loại bỏ khóa chứa some unique stringhoặc chỉ xóa authorized_keystệp khi không còn khóa nào khác.
if test -f $HOME/.ssh/authorized_keys; then
if grep -v "some unique string" $HOME/.ssh/authorized_keys > $HOME/.ssh/tmp; then
cat $HOME/.ssh/tmp > $HOME/.ssh/authorized_keys && rm $HOME/.ssh/tmp;
else
rm $HOME/.ssh/authorized_keys && rm $HOME/.ssh/tmp;
fi;
fi
Thay thế some unique stringbằng một cái gì đó chỉ tồn tại trong khóa bạn muốn loại bỏ.
Là một oneliner trên ssh, điều này trở thành
ssh hostname 'if test -f $HOME/.ssh/authorized_keys; then if grep -v "some unique string" $HOME/.ssh/authorized_keys > $HOME/.ssh/tmp; then cat $HOME/.ssh/tmp > $HOME/.ssh/authorized_keys && rm $HOME/.ssh/tmp; else rm $HOME/.ssh/authorized_keys && rm $HOME/.ssh/tmp; fi; fi'
Đã thử nghiệm trên Linux (SLES) và HP-UX.