diff --git a/java/com.sap.sse.landscape.aws/src/com/sap/sse/landscape/aws/impl/AwsInstanceImpl.java b/java/com.sap.sse.landscape.aws/src/com/sap/sse/landscape/aws/impl/AwsInstanceImpl.java index 26f7f6787b1..8fe03fcc341 100755 --- a/java/com.sap.sse.landscape.aws/src/com/sap/sse/landscape/aws/impl/AwsInstanceImpl.java +++ b/java/com.sap.sse.landscape.aws/src/com/sap/sse/landscape/aws/impl/AwsInstanceImpl.java @@ -199,27 +199,32 @@ public class AwsInstanceImpl implements AwsInstance { " with key "+optionalKeyName+ " to instance with ID "+getInstanceId()); Channel result; - try { - result = Wait.wait(()->{ - Session session = null; - try { - session = createSshSession(sshUserName, optionalKeyName, privateKeyEncryptionPassphrase); - session.setUserInfo(new YesUserInfo()); - session.connect(optionalTimeout.map(d->d.asMillis()).orElse(0l).intValue()); - return session.openChannel(channelType); - } catch (JSchException | IllegalStateException e) { - if (session != null) { - session.disconnect(); - } - throw e; - } - }, - channel->channel != null, - /* retryOnException */ true, optionalTimeout, - Duration.ONE_SECOND.times(5), Level.INFO, - "Trying to connect to " + getInstanceId() + " with user " + sshUserName + " using SSH"); - } catch (TimeoutException timeout) { + if (!optionalKeyName.isPresent() && !Util.hasLength(getInstance().keyName())) { + logger.severe("SSH connection to "+this+" cannot be made because no key name is provided, neither explicitly nor during start-up"); result = null; + } else { + try { + result = Wait.wait(()->{ + Session session = null; + try { + session = createSshSession(sshUserName, optionalKeyName, privateKeyEncryptionPassphrase); + session.setUserInfo(new YesUserInfo()); + session.connect(optionalTimeout.map(d->d.asMillis()).orElse(0l).intValue()); + return session.openChannel(channelType); + } catch (JSchException | IllegalStateException e) { + if (session != null) { + session.disconnect(); + } + throw e; + } + }, + channel->channel != null, + /* retryOnException */ true, optionalTimeout, + Duration.ONE_SECOND.times(5), Level.INFO, + "Trying to connect to " + getInstanceId() + " with user " + sshUserName + " using SSH"); + } catch (TimeoutException timeout) { + result = null; + } } return result; }