Skip to content

Instantly share code, notes, and snippets.

@krmahadevan
Created October 28, 2011 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krmahadevan/1321719 to your computer and use it in GitHub Desktop.
Save krmahadevan/1321719 to your computer and use it in GitHub Desktop.
Steps to recreate the sshj issue
1. create a ‘~/.ssh/config’ file with the following content;
#
# All hosts defaults
#
Host *
Protocol 1,2
FallBackToRsh no
ForwardAgent yes
ForwardX11 yes
PasswordAuthentication yes
RhostsAuthentication no
RhostsRSAAuthentication no
RSAAuthentication yes
NoHostAuthenticationForLocalhost yes
StrictHostKeyChecking no
KeepAlive yes
2. now for this user id, connect to a remote UNIX machine. The moment you connect to a UNIX remote machine, you will see the RSA1 come up.
3. Verify that the key got added up to your ~/.ssh/known_hosts file.
4. Create a SSHv1 compatible key pair using the command "ssh-keygen -t rsa1".
This command will create identity(private key) and identity.pub (public key) and save it under ~/.ssh folder.
5. Verify that the public key looks like a sshv1 key by running cat ~/.ssh/identity.pub
6. Now try to do a passwordless setup to a remote machine, so that no password is asked by running scp ~/.ssh/identity.pub <username>@<machinename>:~/.ssh/
7. Now append it to the authorized keys by running cat ~/.ssh/identity.pub > ~/.ssh/authorized_keys on the remote machine.
8. Verify that the passwordless setup was indeed completed by running ssh <userName>@<machineName> from your local machine, and you shouldn't be prompted for a password.
9. Now try to run the following sample program to simulate the problem from your local machine.
SSHClient client = new SSHClient();
client.loadKnownHosts();
client.connect(REMOTE_MACHINE);
client.authPassword(USERNAME, PASSWORD);
Session session = client.startSession();
Command command = session.exec("who am i");
String output = command.getOutputAsString();
System.out.println(output);
session.close();
client.close();
@krmahadevan
Copy link
Author

krmahadevan commented Jan 19, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment