Last active
March 29, 2026 10:28
-
-
Save Himura2la/35887c73cb3f1fed4c64097e4a93c488 to your computer and use it in GitHub Desktop.
SSH key rotation function
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
| upd_key() { | |
| local old_public_key='ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPHZEGTS/7CdQtGPduRCz0Ie0FMJgfIVvSWkxz1pzmst' | |
| local old_private_key_path=~/.ssh/2022/id_ed25519 | |
| local new_pub_key="$(cat ~/.ssh/id_ed25519.pub)" | |
| ssh -i "$old_private_key_path" -- "$1" \ | |
| "sed -i 's|^${old_public_key}\\([[:space:]].*\\)\\?[[:space:]]*$|${new_pub_key}|' ~/.ssh/authorized_keys" | |
| ssh "$1" 'cat ~/.ssh/authorized_keys' | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment