Skip to content

Commit

Permalink
fix: support non-standard ssh port
Browse files Browse the repository at this point in the history
Parse local ssh server config to find which port to scan for pubkey

Closes fusioninventory#504
  • Loading branch information
g-bougard committed Oct 2, 2018
1 parent 80abec7 commit 3c189bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ inventory:
parsing may fail if a proxy is enabled
* Fix #473: fix arch detection under MacOS
* Fix #475: fix video cards support under MacOS
* Fix #504: support non-standard ssh port to report local ssh server pubkey

deploy:
* Bump Deploy task version to 2.7
Expand Down
13 changes: 12 additions & 1 deletion lib/FusionInventory/Agent/Task/Inventory/Generic/SSH.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,21 @@ sub doInventory {

my $inventory = $params{inventory};

my $port;
my $command = "ssh-keyscan";
if (-e '/etc/ssh/sshd_config') {
foreach my $line (getAllLines( file => '/etc/ssh/sshd_config' )) {
next unless $line =~ /^Port\s+(\d+)/;
$port = $1;
}
}
$command .= " -p $port" if $port;

# Use a 1 second timeout instead of default 5 seconds as this is still
# large enough for loopback ssh pubkey scan.
$command .= ' -T 1 127.0.0.1';
my $ssh_key = getFirstMatch(
command => 'ssh-keyscan -T 1 127.0.0.1',
command => $command,
pattern => qr/^[^#]\S+\s(ssh.*)/,
@_,
);
Expand Down

0 comments on commit 3c189bb

Please sign in to comment.