createPasswordLessSshConnection method
Future<bool>
createPasswordLessSshConnection(
- String username,
- InternetAddress ip, {
- bool addHostToKnownHosts = true,
Implementation
Future<bool> createPasswordLessSshConnection(
String username,
InternetAddress ip, {
bool addHostToKnownHosts = true,
}) async {
final isDeviceReachable = await tryPingDevice(
ip.address,
ip.type == InternetAddressType.IPv6,
);
if (!isDeviceReachable) {
logger.info(
'Could not reach the device with the given IP-address.',
);
final continueWithoutPing = interaction.confirm(
'Do you want to continue anyway?',
defaultValue: true, // this is optional
);
if (!continueWithoutPing) {
logger.spaces();
logger.info('Check your device IP-address and try again.');
return false;
}
}
logger.spaces();
final progress = interaction.progress(
'Preparing SSH connection',
);
// create a directory in the user's home directory
final snappCliDirectory = await createSnappCliDirectory();
final sshKeys = await generateSshKeyFile(processRunner, snappCliDirectory);
await addSshKeyToAgent(sshKeys.privateKey);
progress.complete('Preparing SSH connection completed');
await copySshKeyToRemote(
sshKeys.publicKey,
username,
ip,
);
logger.spaces();
return true;
}