简体   繁体   中英

How do I change the command sent by TRAMP in Emacs when using plink on Windows?

I have the following in my .emacs:

(require 'tramp)
(setq tramp-default-method "plink")

When I run Cx Cf /plink:some_session:/ in Emacs where some_session is a defined session in PuTTY (which has all information saved such as location of private key, username, connection type=ssh, etc.), tramp issues the following command (copied from *Messages* buffer):

Tramp: Sending command ‘plink -ssh -t some_session " env 'TERM=dumb' 'PROMPT_COMMAND=' 'PS1=#$ ' /bin/sh " && exit || exit’

You can see that it passes the -ssh flag to plink . Everything works fine when I am connecting to a remote host which expects the ssh connection on port 22.

However, I have a remote host which I need to connect to on port 2222. If I save a session ( some_new_session ) in PuTTY and try to connect using the following commands (or the PuTTY gui) this is what happens:

  • using the PuTTY GUI
    • works fine
  • plink some_new_session
    • Issued from cmd.exe - works fine and am able to connect
  • plink -ssh some_new_session
    • Issued from cmd.exe - does not work

I have debugged the issue and found that when the -ssh flag is passed to plink it attempts to connect on port 22 anyway even though the saved session states to use port 2222. Essentially when given -ssh it ignores the port saved in the session (which feels like a bug).

If I try to connect using Cx Cf /plink:some_new_session:/ in Emacs the command issued is:

Tramp: Sending command ‘plink -ssh -t some_new_session " env 'TERM=dumb' 'PROMPT_COMMAND=' 'PS1=#$ ' /bin/sh " && exit || exit’

I actually do not need the -ssh flag because the connection type being SSH is saved in the PuTTY session. Also the -ssh flag forces the connection to be through port 22 even though the session has it saved as port 2222.

My question is:

How can I change the command issued by tramp so it does not call plink with the -ssh flag?

The plink method is intended to use a hostname. If you want to (reuse) a session, use plinkx , like Cx Cf /plinkx:some_session:/ and Cx Cf /plink:some_new_session:/ .

I suspect modifying the following will resolve the problem. The value I'm setting here is simply the default tramp-login-args value for the "plink" method.

nb The other standard tramp methods using plink are: "psftp", "pscp", and "plinkx".

(eval-after-load "tramp"
  '(setf (cadr (assq 'tramp-login-args (cdr (assoc "plink" tramp-methods))))
         '(("-l" "%u") ("-P" "%p") ("-ssh") ("-t") ("%h") ("\"")
           ("env 'TERM=dumb' 'PROMPT_COMMAND=' 'PS1=#$ '") ("/bin/sh") ("\""))))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM