0

I thought this should be an extremely basic question, but googling has only revealed one other question on here [1], which did not help.

I have a rather extensive ssh config. How do I get TRAMP to respect it? Most things work out of the box, except for the username, for which TRAMP prompts me for every single server. I would like TRAMP to stop prompting me and just use the "user" entry from my ssh config. Is there a setting for this?

Edit: TRAMP only prompts when the config uses canonicalisation. That is, the following ssh config works:

Host foo
  HostName foo.example.com
  User BettaGeorge

However, the following instead prompts me for a username:

CanonicalDomains example.com
CanonicalizeHostname yes

Host *.example.com
  User BettaGeorge

Setting the username per-host (without wildcards) is not an option since I manage a large cluster of occasionally short-lived virtual machines.

I have confirmed that tramp-default-user-alist is nil when this happens.

My emacs version is 27.2 on linux, my TRAMP version is 2.4.5.27.2.

[1] Tramp mode in emacs using ssh config

Betta George
  • 121
  • 5
  • Check your `tramp-default-user-alist` for conflicting entries. FWIW, I cannot reproduce your problem. With an entry like the one Michael Albinus shows in his answer (and no conflicting entries in `tramp-default-user-alist`) I can access the remote host with no prompt and any one of `scp`, `ssh`, `sshx` protocols. – NickD Dec 03 '21 at 06:02
  • Indeed, you are right. I can get it to work with a minimal ssh config. However, as soon as I add hostname canonicalisation, TRAMP fails. I have edited my question to provide examples. – Betta George Dec 04 '21 at 00:02

1 Answers1

2

If you have a config like

Host xxx
  HostName yyy
  User zzz

it shall be possible to open /ssh:xxx:. Tramp uses then user name zzz and host name yyy. Does this work for you?

Michael Albinus
  • 1,571
  • 9
  • 19
  • That's what I figured, but it does not. TRAMP prompts me anyway. As far as I understand the documentation, this is intended behaviour: "A Caution: TRAMP will override any default user specified in the configuration files outside Emacs, such as ~/.ssh/config." Cited from the html documentation: https://www.gnu.org/software/tramp/#Default-User – Betta George Dec 02 '21 at 21:28
  • 2
    What you quote only applies if `tramp-default-user-alist` contains an entry conflicting with the one in your `~/.ssh/config`: in that case the alist entry wins; but as the doc states "To stop TRAMP from applying the default value, set the corresponding alist entry to nil". – NickD Dec 03 '21 at 06:00
  • Which Emacs/Tramp versions are you using? Have you tried it with `emacs -Q`? – Michael Albinus Dec 03 '21 at 08:33
  • `tramp-default-user-alist` is `nil`. I have pinpointed that the problem is not with usernames per se, it is with hostname canonicalisation. See my edited question for details. I have also added version information to the question. – Betta George Dec 04 '21 at 00:04
  • 1
    Tramp hasn't implemented canonicalization. I'll add it to the TODO section of tramp-sh.el, but I cannot promise any due date for implementation. – Michael Albinus Dec 04 '21 at 08:35
  • That's too bad. Thank you! – Betta George Dec 05 '21 at 00:08