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

Dealing with ssh configuration #23

Closed
marcraminv opened this issue Feb 18, 2020 · 6 comments · Fixed by #24
Closed

Dealing with ssh configuration #23

marcraminv opened this issue Feb 18, 2020 · 6 comments · Fixed by #24

Comments

@marcraminv
Copy link
Contributor

Hey 👋
I am trying to use the library through the ssh configuration, but I capture this error:

Caused by: net.schmizz.sshj.userauth.UserAuthException: Problem getting private key from PKCS8KeyFile{resource=[PrivateKeyFileResource] /Users/marc/.ssh/id_rsa}
at net.schmizz.sshj.userauth.method.KeyedAuthMethod.putSig(KeyedAuthMethod.java:61)
at net.schmizz.sshj.userauth.method.AuthPublickey.sendSignedReq(AuthPublickey.java:74)
at net.schmizz.sshj.userauth.method.AuthPublickey.handle(AuthPublickey.java:45)
at net.schmizz.sshj.userauth.UserAuthImpl.handle(UserAuthImpl.java:142)
at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:500)
at net.schmizz.sshj.transport.Decoder.decodeMte(Decoder.java:159)
at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:79)
at net.schmizz.sshj.transport.Decoder.received(Decoder.java:231)
at net.schmizz.sshj.transport.Reader.run(Reader.java:59)
Caused by: java.io.IOException: unrecognised object: OPENSSH PRIVATE KEY

I have set my stfpSetting like this:

val sftpSettings: IO[SecureFtpSettings] =  IO.pure(SecureFtpSettings(
    host = "localhost",
    port = 2222,
    credentials = FtpCredentials("foo", "bar"),
    strictHostKeyChecking = false,
    knownHosts = None,
    sftpIdentity = Some(KeyFileSftpIdentity("/Users/myname/.ssh/id_rsa", None)),
    sshConfig = new net.schmizz.sshj.DefaultConfig()
  )
)

but I am not sure if I am missing something. If @regis-leray you can give me a tip, I will add it in the documentation for sure 😄

@regis-leray
Copy link
Owner

regis-leray commented Feb 18, 2020

Thanks for your feedback.
So can please give more informations :

  • how did you setup your ftp server
  • how did you generate your ssh key
  • also can you activate debug log level
  • can you provide the all stacktrace ?

Also based on your exception you are getting

Caused by: net.schmizz.sshj.userauth.UserAuthException: Problem getting private key from PKCS8KeyFile{resource=[PrivateKeyFileResource] /Users/marc/.ssh/id_rsa}

i did some research on sshj and i found this issue hierynomus/sshj#437
you might need to regenerate your ssh key as suggested.
or you are might missing authorized keys hierynomus/sshj#159

thanks

@marcraminv
Copy link
Contributor Author

Sure! Sorry to be ambiguous with the information, I start again 😄

how did you setup your ftp server
I am using this sftp docker image to up the server with this configuration for .ssh with my key

running as:

docker run -it --name ssh_test -p 2222:22 -v ~/.ssh/id_rsa.pub:/home/foo/.ssh/keys/id_rsa.pub:ro atmoz/sftp foo::1001

how did you generate your ssh key
I remember to use the same way that github recommend

can you provide the all stacktrace ?

net.schmizz.sshj.userauth.UserAuthException: Exhausted available authentication methods
at net.schmizz.sshj.SSHClient.auth(SSHClient.java:230)
at net.schmizz.sshj.SSHClient.authPublickey(SSHClient.java:345)
at net.schmizz.sshj.SSHClient.authPublickey(SSHClient.java:363)
at ray.fs2.ftp.SFtp$.initKey$1(SFtp.scala:128)
at ray.fs2.ftp.SFtp$.setIdentity(SFtp.scala:138)
at ray.fs2.ftp.SFtp$.$anonfun$connect$5(SFtp.scala:113)
at ray.fs2.ftp.SFtp$.$anonfun$connect$5$adapted(SFtp.scala:113)
at scala.Option.foreach(Option.scala:437)
at ray.fs2.ftp.SFtp$.$anonfun$connect$2(SFtp.scala:113)
at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:87)
at cats.effect.internals.IORunLoop$.start(IORunLoop.scala:34)
at cats.effect.internals.IOBracket$.$anonfun$apply$1(IOBracket.scala:42)
at cats.effect.internals.IOBracket$.$anonfun$apply$1$adapted(IOBracket.scala:32)
at cats.effect.internals.IORunLoop$RestartCallback.start(IORunLoop.scala:345)
at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:122)
at cats.effect.internals.IORunLoop$.startCancelable(IORunLoop.scala:41)
at cats.effect.internals.IOBracket$BracketStart.run(IOBracket.scala:88)
at cats.effect.internals.Trampoline.cats$effect$internals$Trampoline$$immediateLoop(Trampoline.scala:67)
at cats.effect.internals.Trampoline.startLoop(Trampoline.scala:35)
at cats.effect.internals.TrampolineEC$JVMTrampoline.super$startLoop(TrampolineEC.scala:89)
at cats.effect.internals.TrampolineEC$JVMTrampoline.$anonfun$startLoop$1(TrampolineEC.scala:89)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:94)
at cats.effect.internals.TrampolineEC$JVMTrampoline.startLoop(TrampolineEC.scala:89)
at cats.effect.internals.Trampoline.execute(Trampoline.scala:43)
at cats.effect.internals.TrampolineEC.execute(TrampolineEC.scala:42)
at cats.effect.internals.IOBracket$BracketStart.apply(IOBracket.scala:69)
at cats.effect.internals.IOBracket$BracketStart.apply(IOBracket.scala:49)
at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:139)
at cats.effect.internals.IORunLoop$.start(IORunLoop.scala:34)
at cats.effect.internals.IOBracket$.$anonfun$apply$1(IOBracket.scala:42)
at cats.effect.internals.IOBracket$.$anonfun$apply$1$adapted(IOBracket.scala:32)
at cats.effect.internals.IORunLoop$RestartCallback.start(IORunLoop.scala:345)
at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:122)
at cats.effect.internals.IORunLoop$.start(IORunLoop.scala:34)
at cats.effect.IO.unsafeRunAsync(IO.scala:258)
at cats.effect.internals.IOPlatform$.unsafeResync(IOPlatform.scala:38)
at cats.effect.IO.unsafeRunTimed(IO.scala:325)
at cats.effect.IO.unsafeRunSync(IO.scala:240)
... 31 elided
Caused by: net.schmizz.sshj.userauth.UserAuthException: Problem getting private key from PKCS8KeyFile{resource=[PrivateKeyFileResource] /Users/marc/ssh_host_rsa_key}
at net.schmizz.sshj.userauth.method.KeyedAuthMethod.putSig(KeyedAuthMethod.java:61)
at net.schmizz.sshj.userauth.method.AuthPublickey.sendSignedReq(AuthPublickey.java:74)
at net.schmizz.sshj.userauth.method.AuthPublickey.handle(AuthPublickey.java:45)
at net.schmizz.sshj.userauth.UserAuthImpl.handle(UserAuthImpl.java:142)
at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:500)
at net.schmizz.sshj.transport.Decoder.decodeMte(Decoder.java:159)
at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:79)
at net.schmizz.sshj.transport.Decoder.received(Decoder.java:231)
at net.schmizz.sshj.transport.Reader.run(Reader.java:59)
Caused by: java.io.IOException: unrecognised object: OPENSSH PRIVATE KEY
at org.bouncycastle.openssl.PEMParser.readObject(Unknown Source)
at net.schmizz.sshj.userauth.keyprovider.PKCS8KeyFile.readKeyPair(PKCS8KeyFile.java:63)
at net.schmizz.sshj.userauth.keyprovider.BaseFileKeyProvider.getPrivate(BaseFileKeyProvider.java:75)
at net.schmizz.sshj.userauth.method.KeyedAuthMethod.putSig(KeyedAuthMethod.java:59)
... 8 more

@regis-leray
Copy link
Owner

Oki thanks i will try to reproduce locally your issue.
i will do my best to give you a feedback today

@regis-leray
Copy link
Owner

@marcraminv i was able to reproduce and fixed the issue, i will try to release something tonight/tomorow

if you want you can still check out my branch an compile a temporary artifact to unlock you
https://github.com/regis-leray/fs2-ftp/pull/24/files

@marcraminv
Copy link
Contributor Author

Thank u a lot @regis-leray , I will add the example for this if you agree. Maybe useful for next users.

@regis-leray
Copy link
Owner

@marcraminv release 0.6.1 is available 🎉

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

Successfully merging a pull request may close this issue.

2 participants