From bb8b9420d6e38c3c9dc93bc6b6517efc1ef62d1b Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Tue, 19 Mar 2024 14:57:55 +0100 Subject: [PATCH] Use rofi for SSH passphrases --- bin/ssh-askpass-rofi | 11 +++++++++++ home/dotfilesrc | 1 + shell/ssh | 21 ++++++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100755 bin/ssh-askpass-rofi diff --git a/bin/ssh-askpass-rofi b/bin/ssh-askpass-rofi new file mode 100755 index 0000000..19b4e22 --- /dev/null +++ b/bin/ssh-askpass-rofi @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +arg="$*" + +key="$(echo "${arg}" | perl -ne "/'(.*)'/"' and print "$1\n"')" +pub="${key}.pub" +fingerprint="$(ssh-keygen -l -v -f "${pub}")" + +mesg="${arg} ${fingerprint} " + +rofi -dmenu -disable-history -no-fixed-num-lines -l 1 -i -input /dev/null -password -p 'Passphrase' -mesg "${mesg}" diff --git a/home/dotfilesrc b/home/dotfilesrc index 5579fb7..0c9f185 100644 --- a/home/dotfilesrc +++ b/home/dotfilesrc @@ -4,5 +4,6 @@ DOTFILES_ROOT_DIR="$(dirname "$DOTFILES_HOME_DIR")" DOTFILES_ZSH_DIR="$DOTFILES_ROOT_DIR/zsh" DOTFILES_BASH_DIR="$DOTFILES_ROOT_DIR/bash" DOTFILES_SHELL_DIR="$DOTFILES_ROOT_DIR/shell" +DOTFILES_BIN_DIR="$DOTFILES_ROOT_DIR/bin" # vim: ft=sh diff --git a/shell/ssh b/shell/ssh index be2a477..44d8bbc 100755 --- a/shell/ssh +++ b/shell/ssh @@ -14,7 +14,7 @@ fi # autoload keys if there's an agent if [[ -n "${SSH_AUTH_SOCK}" ]]; then - if ! ssh-add -l > /dev/null; then + if ! command ssh-add -l > /dev/null; then case "${OSTYPE}" in linux*) # TODO: unsure yet @@ -33,6 +33,25 @@ if [[ -n "${SSH_AUTH_SOCK}" ]]; then ;; esac fi + + case "${OSTYPE}" in + linux*) + SSH_ASKPASS="${DOTFILES_BIN_DIR}/ssh-askpass-rofi" + SSH_ASKPASS_REQUIRE='prefer' + export SSH_ASKPASS SSH_ASKPASS_REQUIRE + ;; + *) + : + ;; + esac fi +function ssh-add() { + if [[ $# -eq 0 ]]; then + command ssh-add ~/.ssh/id_*[!.pub] + else + command ssh-add "$@" + fi +} + # vim: ft=bash