A Man-in-the-Middle (MITM) proxy for the SSH Agent protocol designed to solve the "Too many authentication failures" issue when using memory-based SSH agents like Bitwarden.
When using Bitwarden (or similar agents) with multiple SSH keys, the agent blindly offers every key in your vault to the remote server upon connection. Because OpenSSH does not pass the target hostname to the agent (due to architectural limitations of the REQUEST_IDENTITIES payload), the agent cannot know which key is correct. If you have more keys in your vault than the server's MaxAuthTries limit (usually 5 or 6), the server drops the connection before the correct key is ever tried.
This tool sits between the OpenSSH client and your actual SSH agent. It intercepts the protocol and provides a GUI (zenity) allowing you to manually select the correct key to offer the server.
Additionally, it features an optional Out-of-Band Monitor that captures your CLI ssh commands before they execute, cross-references the hostname with your key comments, and can automatically pick the right key without displaying the GUI.
- Python 3
- zenity (for the GUI selection menu)
- Ubuntu/Debian:
sudo apt install zenity - Fedora/RHEL:
sudo dnf install zenity - Arch:
sudo pacman -S zenity
- Ubuntu/Debian:
Create a dedicated directory in your local bin folder and download the script there.
mkdir -p ~/.local/bin/fagent
wget -O ~/.local/bin/fagent/fagent.py https://raw.githubusercontent.com/abyani/fagent/main/fagent.py
chmod +x ~/.local/bin/fagent/fagent.pyYou need to point the script to your real agent (Backend) and tell it where to open the new Proxy socket.
- Bitwarden (Manual/Standard Install):
~/.local/bin/fagent/fagent.py -b ~/.bitwarden-ssh-agent.sock -p /tmp/ssh-proxy.sock
- Bitwarden (Flatpak):
~/.local/bin/fagent/fagent.py -b ~/.var/app/com.bitwarden.desktop/data/ssh-auth.sock -p /tmp/ssh-proxy.sock
Update your shell configuration file to point SSH_AUTH_SOCK to the new proxy instead of Bitwarden directly.
- Bash / Zsh (Add to
~/.bashrcor~/.zshrc):export SSH_AUTH_SOCK=/tmp/ssh-proxy.sock - Fish (Add to
~/.config/fish/config.fish):set -e SSH_AUTH_SOCK set -gx SSH_AUTH_SOCK /tmp/ssh-proxy.sock
Restart your terminal. Now, every time you SSH into a server, a GUI window will pop up allowing you to select exactly which key to offer.
To bypass the OpenSSH "blindness" limitation, you can configure your shell to send your intended SSH target (e.g., root@192.168.1.10) to the proxy script via a background socket before the SSH client connects. If exactly one key matches the command, it bypasses the GUI completely. If multiple match, it opens the GUI with the matches highlighted at the top.
Add the --auto-pick flag when starting the proxy. You can also define a custom monitor socket path using the -m flag (it defaults to /tmp/ssh-monitor.sock if omitted):
~/.local/bin/fagent/fagent.py \
-b ~/.bitwarden-ssh-agent.sock \
-p /tmp/ssh-proxy.sock \
-m /tmp/ssh-monitor.sock \
--auto-pickYou must intercept the ssh command in your terminal so it reports its arguments to the proxy's monitor socket. We use a lightweight Python one-liner to do this reliably. Ensure the socket path in your function matches the path you defined with the -m flag above.
- Bash / Zsh (Add to
~/.bashrcor~/.zshrc):ssh() { python3 -c 'import sys, socket; s=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM); s.settimeout(1); s.connect("/tmp/ssh-monitor.sock"); s.sendall(" ".join(sys.argv[1:]).encode())' "$@" 2>/dev/null /usr/bin/ssh "$@" }
- Fish (Add to
~/.config/fish/config.fish):function ssh python3 -c 'import sys, socket; s=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM); s.settimeout(1); s.connect("/tmp/ssh-monitor.sock"); s.sendall(" ".join(sys.argv[1:]).encode())' $argv 2>/dev/null command ssh $argv end
Key Naming Requirement: In order for the auto-pick feature to find a match, the Item Name in your Bitwarden vault (which the underlying agent protocol sees as the key's "comment" field) must contain the hostname, IP address, or subdomain you intend to connect to. If your key is simply named "My Web Server," the script cannot logically link it to ssh root@192.168.1.50.
To ensure the proxy runs automatically in the background on startup, you can configure it as a user-level systemd service.
-
Create the systemd user directory (if it doesn't exist):
mkdir -p ~/.config/systemd/user -
Create the service file: Open a new file at
~/.config/systemd/user/fagent.servicein your preferred text editor and paste the following configuration.Note: This configuration assumes you installed
fagent.pyto~/.local/bin/fagent/as described in step 1. Use%has a variable for your home directory to locate the files.[Unit] Description=fagent - SSH Agent MITM Proxy for Bitwarden After=network.target [Service] Type=simple # Note: Modern desktop environments (GNOME/KDE) usually inject these graphical # variables into systemd automatically. If zenity fails to open a window # or crashes in the background, uncomment the lines below to force them. #Environment="DISPLAY=:0" #Environment="WAYLAND_DISPLAY=wayland-0" #Environment="DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/%U/bus" # Adjust paths as needed for your specific setup ExecStart=/usr/bin/python3 %h/.local/bin/fagent/fagent.py \ -b %h/.bitwarden-ssh-agent.sock \ -p /tmp/ssh-proxy.sock \ -m /tmp/ssh-monitor.sock \ --auto-pick Restart=on-failure RestartSec=5 [Install] WantedBy=default.target
-
Reload systemd, enable, and start the service:
systemctl --user daemon-reload systemctl --user enable fagent.service systemctl --user start fagent.service -
Verify it is running:
systemctl --user status fagent.service
Please note that the entirety of this program, including the Python source code and this README file, was generated using Google Gemini with minimal human supervision.
Security Note: Despite being AI-generated, this program cannot access or compromise your sensitive data (like your SSH private keys). By design, the SSH Agent protocol never transmits private keys over the socket. The backend agent (e.g., Bitwarden) handles all cryptographic signing internally and only exposes public keys and key comments to the proxy. Your actual private keys remain securely locked in your vault and are never exposed to this script.