masasam/emacs-counsel-tramp

Allow connecting with a different username

Closed this issue · 6 comments

I have connections set up in .ssh/config that have a different user name provided through User. However, counsel-tramp seems to always pick up my current login name, which is problematic. Can this be fixed?

FYI, this works fine with regular tramp over ivy/counsel.

Hi @swarnendubiswas .
Thank you for comment.

Counsel-tramp expects Host to have one User.
In case of ~/.ssh/config like below, it is always ec2-user.

Host myserver
		HostName 1.1.1.1
		User ec2-user

Host myserver
		HostName 1.1.1.1
		User admin

This is because ssh myserver command always connect with ec2-user.
Do the following to connect with admin.

Host myserver
		HostName 1.1.1.1
		User ec2-user

Host myserver-admin
		HostName 1.1.1.1
		User admin

Ok, but my hostnames are different. Here is a sample.

Host A-XXX
  HostName YYY
  User AAA

Host B-XXX
  HostName YYY
  User BBB

Suppose my Linux user name is AAA. Now if I do counsel-tramp to B-XXX, the minibuffer prompt shows that the user name used for authentication is still AAA instead of BBB.

I've tried this example and it seems to be fine.
Please tell me a little more detail.

Screenshot from 2020-05-04 23-33-23

~/.ssh/config

Host a-instance
		HostName *.*.*.*
		User masa

Host b-instance
		HostName *.*.*.*
		User masasam

I had (tramp-default-user user-login-name), so I think that is why the user-login-name is being picked as default.

My point is if an User field is provided in .ssh/config, then maybe the provided User name should override user-login-name.

I tried connecting again aftering commenting out (tramp-default-user user-login-name). So now, the default user-login-name is not being used which is good. But counsel-tramp is still prompting the following in the minibuffer: ssh user name for B-XXX (default AAA): . This is even after I have configured B-XXX in .ssh/config with username BBB.

Hmm, the document of of tramp-default-user says the following.

It is nil by default; otherwise settings in configuration files like
"~/.ssh/config" would be overwritten.  Also see tramp-default-user-alist.

Hmm, so that invalidates the first question that I had. But could the second request be implemented?

I've confirmed.
I may implement it if there is any good way, but I think this is difficult.