diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh index becd5ea17..acf56cc35 100644 --- a/plugins/ssh-agent/ssh-agent.plugin.zsh +++ b/plugins/ssh-agent/ssh-agent.plugin.zsh @@ -44,8 +44,8 @@ function _add_identities() { if [[ ${#identities[@]} -eq 0 ]]; then # Iterate over files in .ssh folder. for file in "$HOME/.ssh"/*; do - # Check if file is a regular file and starts with "-----BEGIN OPENSSH PRIVATE KEY-----". - if [[ -f "$file" && $(command head -n 1 "$file") =~ ^-----BEGIN\ OPENSSH\ PRIVATE\ KEY----- ]]; then + # Check if file is a valid private key using file magic. + if [[ -f "$file" && $(file -b "$file") == *"private key"* ]]; then # Add filename (without path) to identities array. identities+=("${file##*/}") fi