7

I want to call the ssh-add shell command. So I invoke M-x shell-command RET, and in the minibuffer, I type: ssh-add .ssh/id_rsa

The only thing I get is:

ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory^M

How can I make Emacs give me another prompt, so I can type the passphrase ssh-add is waiting for?

This is with Emacs under X11 on Debian.

2

The easy way would be to install ssh-askpass. This is the program that ssh-add runs when its standard input is not a terminal but an X11 display is available. The program ssh-askpass prompts for your passphrase in a separate GUI window.

If you want to stay within Emacs, or if you want a solution that works whether X11 is available or not, you can make Emacs prompt for the passphrase. Here's some Lisp code (minimally tested) to do this.

(defun ssh-add-process-filter (process string)
  (save-match-data
    (if (string-match ":\\s *\\'" string)
        (process-send-string process (concat (read-passwd string) "\n"))
      (message "%s" string))))
(defun ssh-add (key-file)
  "Run ssh-add to add a key to the running SSH agent.
Let Emacs prompt for the passphrase."
  (interactive "fAdd key: \n")
  (let ((process-connection-type t)
            process)
    (unwind-protect
        (progn
          (setq process (start-process "ssh-add" nil
                                       "ssh-add" (expand-file-name key-file)))
          (set-process-filter process 'ssh-add-process-filter)
          (while (accept-process-output process)))
      (if (eq (process-status process) 'run)
          (kill-process process)))))
1

The simplest way to go about this is use M-x shell instead of shell-command. M-x shell is an actual shell, not just a prompt, and it should be capable of shallow interactions such as this.

Whenever you need to use a shell command and even shell isn't doing what you need, call M-x term instead, which is an actual terminal emulator and should be capable of performing most tasks.

  • This is actually the way I'm doing. The interesting thing would be: being able to add my ssh key to the ssh-agent without being obliged to launch a whole shell & without leaving the current buffer. – Nsukami _ Sep 25 '14 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.