File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Java  SSH method on Unix Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "Java  SSH method on Unix " Watch "Java  SSH method on Unix " New topic
Author

Java SSH method on Unix

terry Kiernan
Ranch Hand

Joined: Aug 23, 2008
Posts: 31
Hi ,

Anyone know how I can ssh using a java method into another machine where authentication has already been setup for the user ...

Please Help as I am stuck , I was using a third party trilead plugin methods but it looks like that plugin methods doesn't work .

Thanking you ,
T
sangram mhatre
Greenhorn

Joined: Apr 02, 2005
Posts: 15
I have used a third party api from jscape and it works fine
and is simple to use . You can try the same .
http://www.jscape.com/articles/ssh_using_java.html
terry Kiernan
Ranch Hand

Joined: Aug 23, 2008
Posts: 31
Thanks for that ... BUT I don't want to enter the password .. I have already authenticated the user so s/he should be able to ssh just passing the hostname and username no Need for password ...

It looks like Jscape requires the password to be passed in ...???
sangram mhatre
Greenhorn

Joined: Apr 02, 2005
Posts: 15
No , you dont have to .
you can refer the api at , http://www.jscape.com/secureinetfactory/docs/javadoc/index.html

Check for ssh constructor .
terry Kiernan
Ranch Hand

Joined: Aug 23, 2008
Posts: 31
Yeah have been looking at that class definitions but I don't see a constructor that only takes the username and hostname ... Maybe i am missing something ???...

Thanks your help is been much appreciated ...

BTW : this is not Freeware ? had you to purchase the jscape package ..
terry Kiernan
Ranch Hand

Joined: Aug 23, 2008
Posts: 31
i am geteting the following error when i just pass username and hostname to the construtor
ymbol : constructor SshParameters(java.lang.String,java.lang.String)
location: class com.jscape.inet.ssh.util.SshParameters
SshParameters sshParams = new SshParameters(hostname,username);
Carey Evans
Ranch Hand

Joined: May 27, 2008
Posts: 225

Can you expand on what you mean when you say that you �have already authenticated the user�, and why this should let you access another machine without logging in?
terry Kiernan
Ranch Hand

Joined: Aug 23, 2008
Posts: 31
Hi Carey,

when i say that I mean the user can login into the hostname without providing the password . The the rsa and dsa keys have been generated outside the application for that user.

So for eg the user can do the following from one host to another remote host where authenticiy has ben established.

ssh -l <username> <hostname>
Carey Evans
Ranch Hand

Joined: May 27, 2008
Posts: 225

With Trilead SSH, you can use Connection.authenticateWithPublicKey() with the filename of the key. It won't find the key automatically.
terry Kiernan
Ranch Hand

Joined: Aug 23, 2008
Posts: 31
Carey,
there is a method
boolean res = conn.authenticateWithNone(username);

if (res == true)
{
("No authentication needed.");
}
if (res == false)
{
("Authentication needed:");

}
so that should do it But No ....
Carey Evans
Ranch Hand

Joined: May 27, 2008
Posts: 225

"none" authentication is used in SSH when the connection doesn't need to be authenticated at all, not when it uses public key authentication.

I believe "none" will only work with OpenSSH if you've configured "hostbased" authentication on both the client and the server, which is not a simple process. I don't know if any Java SSH clients support it, but I also doubt that you're using it.
terry Kiernan
Ranch Hand

Joined: Aug 23, 2008
Posts: 31
Hi,

I am using the Jscape package now to do use the ssh session within java ..
How ever it is a licenced package ... Do I have to purchase the licence for it to run with this .. Is there any ssh session package that is GPL and free to use ?
As anyone been faced with this before ?

Thanks
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
If you are going to do that, why bother with authentication?

What you are asking is how to authenticate an IP address and then assume that only the one person who authenticated will use the machine.

See a problem with that?


"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Java SSH method on Unix
 
Similar Threads
Runtime.exec( "ssh" )?
Wagon-ssh with Maven 2.2
ssh example in java.
Moving huge data from Client to Server
Eclipse: ssh plugin ?