Fix: Support all SSH private key formats in ssh-agent plugin

The previous implementation only supported OpenSSH private keys, which start with "-----BEGIN OPENSSH PRIVATE KEY-----". This commit improves the plugin to support all valid private key formats by using the 'file' command to identify them based on their content.

This change ensures that the ssh-agent plugin can handle keys in various formats, including PKCS#1, PKCS#8, and OpenSSH.
This commit is contained in:
mikhailde 2024-10-14 17:16:31 +03:00
commit 2f5817c258

View file

@ -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