From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Roland Winkler Newsgroups: gmane.emacs.help Subject: tramp and ssh-agent / ssh-add Date: Sun, 30 Mar 2008 01:53:23 +0100 Organization: FAU Erlangen-Nuernberg Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1206841251 5303 80.91.229.12 (30 Mar 2008 01:40:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 30 Mar 2008 01:40:51 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Mar 30 03:41:22 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JfmXv-0000us-7w for geh-help-gnu-emacs@m.gmane.org; Sun, 30 Mar 2008 03:41:19 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JfmXJ-0008AD-Gl for geh-help-gnu-emacs@m.gmane.org; Sat, 29 Mar 2008 21:40:41 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!news.dfncis.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 46 Original-X-Trace: news.dfncis.de 1Fpb0FZw/B1I0Yb4IA+dyw1XiASkOSOzdIsNv/HwvQZRpl Cancel-Lock: sha1:hO7s/HCroBdidGydfsazvOXmBPc= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Original-Xref: shelby.stanford.edu gnu.emacs.help:157439 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:52810 Archived-At: 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)))