Browse Source

feat(ssh-agent): add keys regardless of filename (#12741)

Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
Щанников Михаил 1 month ago
parent
commit
d2d5155d41
1 changed files with 10 additions and 7 deletions
  1. 10 7
      plugins/ssh-agent/ssh-agent.plugin.zsh

+ 10 - 7
plugins/ssh-agent/ssh-agent.plugin.zsh

@@ -39,13 +39,16 @@ function _add_identities() {
     return
     return
   fi
   fi
 
 
-  # add default keys if no identities were set up via zstyle
-  # this is to mimic the call to ssh-add with no identities
-  if [[ ${#identities} -eq 0 ]]; then
-    # key list found on `ssh-add` man page's DESCRIPTION section
-    for id in id_rsa id_dsa id_ecdsa id_ed25519 id_ed25519_sk identity; do
-      # check if file exists
-      [[ -f "$HOME/.ssh/$id" ]] && identities+=($id)
+  # If no keys specified in zstyle, add default keys.
+  # Mimics calling ssh-add with no arguments.
+  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
+        # Add filename (without path) to identities array.
+        identities+=("${file##*/}")
+      fi
     done
     done
   fi
   fi