Rex
Rex copied to clipboard
Get default user from ssh config file
Currently rex tries to get the username to be used for making an SSH connection from different places, in order as seen in Rex::Config->get_user
:
-
REX_USER
environment variable -
user
setting in Rexfile -
getlogin
-
getpwuid($<)
It would be nice if we could try using the username set in ~/.ssh/config
for a given host. Reading and parsing the SSH config file is already there in Rex::Config
, but we probably need to somehow pass the servername in question and see if it matches any of the SSH config entries.
+1 for this. I'm currently using the following command inside my Rexfile
in order to interact with Vagrant VMs:
%Rex::Config::SSH_CONFIG_FOR = Rex::Config::_parse_ssh_config(`vagrant ssh-config`);
This one-liner sets up all the necessary host, port, username, auth etc for all of your Vagrantfile VMs in order for you to access them with Rex. However, Rex does not use the user
defined in %Rex::Config::SSH_CONFIG_FOR
. Instead it uses my getlogin
or getpwuid($<)
as noted by @ferki so Rex fails authentication.
I think the order should be:
-
REX_USER
environment variable -
user
setting in Rexfile (which includes-u
from the command line) -
$Rex::Config::SSH_CONFIG_FOR{$host}{user}
-
getlogin
-
getpwuid($<)