Skip to content

Instantly share code, notes, and snippets.

@Himura2la
Last active March 29, 2026 10:28
Show Gist options
  • Select an option

  • Save Himura2la/35887c73cb3f1fed4c64097e4a93c488 to your computer and use it in GitHub Desktop.

Select an option

Save Himura2la/35887c73cb3f1fed4c64097e4a93c488 to your computer and use it in GitHub Desktop.
SSH key rotation function
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