Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid packet exception ssh'ing as root when "Please login as the ubuntu user rather than root user" #75

Closed
aledsage opened this issue May 19, 2012 · 8 comments

Comments

@aledsage
Copy link
Contributor

I have an ubuntu VM that I'm trying to use with the following code:

   public static void main(String[] args) throws IOException {
      String privateKey = "<snip>";
      net.schmizz.sshj.SSHClient ssh = new net.schmizz.sshj.SSHClient();
      ssh.addHostKeyVerifier(new PromiscuousVerifier());
      ssh.connect("54.247.147.118", 22);

      OpenSSHKeyFile key = new OpenSSHKeyFile();
      key.init(privateKey, null);
      ssh.authPublickey("root", key);

      SFTPClient sftpClient = ssh.newSFTPClient();
   }

It gives me the error:

Exception in thread "main" java.lang.IllegalStateException: Invalid packet: indicated length 1349281121 too large
    at net.schmizz.sshj.sftp.PacketReader.readPacket(PacketReader.java:70)
    at net.schmizz.sshj.sftp.SFTPEngine.init(SFTPEngine.java:77)
    at net.schmizz.sshj.SSHClient.newSFTPClient(SSHClient.java:623)
    at org.jclouds.sshj.Main.main(Main.java:42)

Trying to ssh or scp to the machine at the command line with:

ssh -i my_id_rsa root@54.247.147.118

gives:

Please login as the ubuntu user rather than root user.
Connection to 54.247.147.118 closed.

It works when I ssh in as:

ssh -i my_id_rsa ubuntu@54.247.147.118

Is there some different behaviour of the ssh protocol in this situation?

@aledsage
Copy link
Contributor Author

@shikhar
Copy link
Contributor

shikhar commented May 20, 2012

Thanks for the report @aledsage , it's odd that there is different behaviour with the openssh client & with sshj. I will try to reproduce what's going on.

@shikhar
Copy link
Contributor

shikhar commented May 20, 2012

Could you post what you get with

sftp -i my_id_rsa root@54.247.147.118

(sftp command instead of ssh)

@shikhar
Copy link
Contributor

shikhar commented May 20, 2012

So I tried this out, even openssh sftp client bails out...

$ sftp -i sshjaws.pem root@xxxx.compute-1.amazonaws.com
Received message too long 1349281121

So it's not an sshj issue

@shikhar shikhar closed this as completed May 20, 2012
@aledsage
Copy link
Contributor Author

Confirmed I get the same with sftp -oIdentityFile=my_id_rsa root@54.247.147.118, gives:

Connecting to 54.247.147.118...
Received message too long 1349281121

@aledsage
Copy link
Contributor Author

For the benefit of anyone searching for more information on this....

This link explains what's going on in openssh sftp: http://www.snailbook.com/faq/sftp-corruption.auto.html

The problem here is similar to if the underlying ssh command causes stdout (e.g. due to system or per-user shell startup files on the server). The text pollutes the protocol stream between scp2/sftp and sftp-server. The first four bytes of the text gets interpreted as a 32-bit packet length.

@shikhar
Copy link
Contributor

shikhar commented May 20, 2012

That's a good explanation, thanks @aledsage

@stringaro-leo
Copy link

@aledsage '...(like fortune, echo "Hi there!", etc.)....' you saved me, thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants