public function getDefaultUsername()
{
if (is_null($this->username)) {
if ($user = $this->getInspectorConfiguration('user')) {
$this->username = $user;
} elseif ($user = $this->getTag('inspector:user')) {
// deprecated!
$this->username = $user;
} elseif ($user = getenv('AWSINSPECTOR_DEFAULT_EC2_USER')) {
$this->username = $user;
} else {
$this->username = 'ec2-user';
$ami = $this->getImageId();
if (in_array($ami, ['ami-47a23a30', 'ami-47360a30', 'ami-d05e75b8'])) {
$this->username = 'ubuntu';
}
}
}
return $this->username;
}
public function __toString() { $parts = ['ssh']; if ($this->privateKey) { $parts[] = '-i ' . $this->privateKey->getPrivateKeyFile(); } if (!is_null($this->jumpHost)) { if ($output = Registry::get('output')) { /* @var $output OutputInterface */ $output->writeln("[Using jump host: " . $this->jumpHost->getDefaultUsername() . '@' . $this->jumpHost->getPublicIpAddress() . "]"); } $proxyCommand = new Command($this->jumpHost->getSshConnection(), 'nc %h %p'); $parts[] = '-o ProxyCommand="' . $proxyCommand->__toString() . '"'; } if ($this->multiplex) { $connection = "~/mux_{$this->username}@{$this->host}:22"; self::$multiplexedConnections[$connection] = "{$connection} {$this->host}"; $parts[] = "-o ControlPersist=yes -o ControlMaster=auto -S {$connection}"; } $parts[] = '-o ConnectTimeout=5'; //$parts[] = '-o LogLevel=QUIET'; $parts[] = '-o StrictHostKeyChecking=no'; // $parts[] = '-t'; // Force pseudo-tty allocation. $parts[] = "{$this->username}@{$this->host}"; return implode(' ', $parts); }