pytest-testinfra icon indicating copy to clipboard operation
pytest-testinfra copied to clipboard

Paramiko backend overwrites username with ~/.ssh/config defaults

Open kmccormick opened this issue 3 years ago • 0 comments

At the bottom of my ~/.ssh/config, I have this section because my local username doesn't match my most common remote username:

Host *
User kmccormick

When running pytest, any paramiko host always uses the kmccormick user, even though I specify vagrant. It's the same whether it is set on the command line or in conftest.py with get_host, e.g.:

pytest --hosts "paramiko://[email protected]:2222" 
get_host("paramiko://[email protected]:2222")

This breaks the convention with ssh and ssh_config where earlier options override later options; command line options should override anything in ssh_config. It looks like it's had the same behavior since ~/.ssh/config was added as a fallback in 5c3388c4.

_load_ssh_config() should only set cfg["username"] = value if user isn't already set. That should probably also be extended out to other settings besides just username.

I'm working around this by supplying an ssh config file. Even /dev/null will do.

kmccormick avatar Feb 21 '22 23:02 kmccormick