My default-directory is: /ssh:lawlist@12.34.567.89#2222:/home3/lawlist
My .authinfo file contains: machine 12.34.567.89 login lawlist password abcdefg
The above-combination works just fine. However, I would like to remove #2222 from the default-directory and add port 2222 to my .authinfo file.
If I remove #2222 from the default-directory and add port 2222 to my .authinfo file, neither Eshell nor Dired permit me to login to the remote server.
Eshell:
Waiting for prompts from remote shell ...
Timeout reached, see buffer `*tramp/ssh lawlist@12.34.567.89*` for details.
Q: How can I remove #2222 from my default-directory and force Eshell and/or Dired to extract port 2222 from my .authinfo file?
EDIT: The following is rough draft to add this new feature. A maintainer of Tramp, @Michael Albinus, has suggested that this may break other aspects of Tramp and he has invited a discussion on tramp-devel@gnu.org regarding this issue.
Ensure you are using a version of Emacs containing the December 17, 2015 bug fix to
auth-source-ensure-stringsthat was resolved by commit 9384953: https://github.com/jwiegley/emacs/commit/938495317a02b06a6c512832d0c6d9530fcd7f2bDefine the following function:
(defun get-auth-info (host user &optional port)
(let ((info (nth 0 (auth-source-search
:host host
:user user
:port port
:require '(:user :secret)
:create t))))
(if info
(let* ((port (plist-get info :port))
(secret-maybe (plist-get info :secret))
(secret
(if (functionp secret-maybe)
(funcall secret-maybe)
secret-maybe)))
(list port secret))
nil)))
Comment out
:port tramp-current-methodintramp-read-passwd.tramp-current-methodis"ssh"and this preventsauth-source-searchfrom returning a result if.authinfocontains a specified port other thanssh; e.g.,port 2222.Within
tramp-maybe-open-connection, comment out and replace this section as follows:
;; (when (string-match tramp-host-with-port-regexp l-host)
;; (setq l-port (match-string 2 l-host)
;; l-host (match-string 1 l-host)))
(cond
((string-match tramp-host-with-port-regexp l-host)
(setq l-port (match-string 2 l-host)
l-host (match-string 1 l-host)))
((and l-host l-user)
(let ((port (car (get-auth-info l-host l-user))))
(when port
(setq l-port port)))))