diff --git a/src/main/java/com/jcabi/ssh/Ssh.java b/src/main/java/com/jcabi/ssh/Ssh.java index 1caa051..7410d44 100644 --- a/src/main/java/com/jcabi/ssh/Ssh.java +++ b/src/main/java/com/jcabi/ssh/Ssh.java @@ -238,12 +238,11 @@ public static String escape(final String arg) { types = IOException.class ) protected Session session() throws IOException { + final File file = File.createTempFile("jcabi-ssh", ".key"); try { JSch.setConfig("StrictHostKeyChecking", "no"); JSch.setLogger(new JschLogger()); final JSch jsch = new JSch(); - final File file = File.createTempFile("jcabi-ssh", ".key"); - file.deleteOnExit(); new LengthOf( new TeeInput( this.key.replaceAll("\r", "") @@ -277,10 +276,11 @@ protected Session session() throws IOException { ); session.setServerAliveCountMax(Tv.MILLION); session.connect(); - Files.deleteIfExists(file.toPath()); return session; } catch (final JSchException ex) { throw new IOException(ex); + } finally { + Files.deleteIfExists(file.toPath()); } } }