|
|
Usually when I have emacs running on a remote machine, I do this as
a subprocess of ssh-agent. Then when I establish ssh connections
via tramp, I want to make sure that I type my password only once via
ssh-add. What is the cleanest way to do that? Is there some support
from tramp for that? Right now, my home-made solution uses a
defadvice for tramp-open-connection-rsh, see the code below.
However, if tramp-open-connection-rsh is the right entry point for
what I want to do, it seems to me that a hook might be helpful. Or
am I missing something else?
Thanks,
Roland
(defun ssh-add-p ()
"Return t if ssh identities known."
(with-temp-buffer
(call-process "/usr/bin/ssh-add" nil t nil "-l")
(goto-char (point-min))
(not (search-forward "The agent has no identities." nil t))))
(defun ssh-add (&optional password)
"Add ssh passphrase."
(interactive)
(if (ssh-add-p)
(if (interactive-p) (message "Passphrase already entered."))
(with-temp-buffer
(insert (or password (read-passwd "Passphrase: ")) "\n")
(let ((process-environment (copy-alist process-environment)))
(setenv "DISPLAY") ;; unset DISPLAY
(call-process-region (point-min) (point-max)
"/usr/bin/ssh-add" t t nil))
;; Massage output
(goto-char (point-min))
;; suppress "Enter passphrase for ...: "
(search-forward ": " nil t)
(let ((beg (point)))
(goto-char (point-max))
(skip-chars-backward " \t\n")
(message "%s" (buffer-substring-no-properties beg (point)))))))
(defadvice tramp-open-connection-rsh (before ssh-add activate)
"First call `ssh-add'."
(if (string= "ssh" (ad-get-arg 1))
(ssh-add)))
|
|