My scenario:
Step1:Connect to ec2 server using file ".pem"
-host: 52.194.228.89
-port: 22
-username: ec2-user
-File .pem for authorization
Step2: Continue connecting SSH to second server using following command:
Command line: ssh -i ~/.ssh/id_rsa linseed@10.231.14.139
-host: 10.231.14.137
-username: linseed
-password: linseed
=> For step1: I already connected to ec2 server using file .pem successfully. I using Java:
public static Session connectServerAwsOld(String host, int port, String userName, String filePemPath) {
Session session;
JSch jsch = new JSch();
try {
session = jsch.getSession(userName, host, port);
jsch.addIdentity("filePemPath");
session.setConfig("StrictHostKeyChecking", "no");
System.out.println("Establishing Connection...");
session.connect();
System.out.println("Connection established successfully.");
} catch (JSchException e) {
System.out.println("not connected server");
session = null;
}
return session;
}
Result:
Establishing Connection...
Connection established successfully.
=>For Step2: Currently i have not found out the way to implement connection yet like the way i did manually (Command line: ssh -i ~/.ssh/id_rsa linseed@10.231.14.139). Could someone help to take a look on my issue and give me a advice for implement connection? Thanks in advance you guys...