You can create public/private keys on the originating server (using ssh-keygen), copy the public key into the remote host's .ssh/authorized_keys and then pass the private key in as a runtime paramater on the originating machine.

There are examples of this all over the web, but one is here :)

http://stackoverflow.com/questions/4932005/can-we-use-jsch-for-ssh-key-based-communication

On Mon, 4 Jun 2012, Cardician wrote:


So I'm writing a little program that needs to connect to a remote server
through SFTP, pull down a file, and then processes the file. I came across
JSch through some answers on StackOverflow and it looked perfect for the
task. So far, easy to use and I've got it working, with one minor thing I'd
like to fix. I'm using the following code to connect and pull the file down:

    JSch jsch = new JSch();


    Session session = null;
    try {


        session = jsch.getSession("username", "127.0.0.1", 22);


        session.setConfig("StrictHostKeyChecking", "no");


        session.setPassword("password");
        session.connect();


        Channel channel = session.openChannel("sftp");


        channel.connect();
        ChannelSftp sftpChannel = (ChannelSftp) channel;


        sftpChannel.cd(REMOTE_FTP_DIR);
        sftpChannel.lcd(INCOMING_DIR);


        sftpChannel.get(TMP_FILE, TMP_FILE);


        sftpChannel.exit();
        session.disconnect();


    } catch (JSchException e) {


        e.printStackTrace();
    } catch (SftpException e) {


        e.printStackTrace();
    }

So this works and I get the file. I'm running this code on a linux server
and when I run the code JSch asks me for my Kerberos username and password.
It looks like:

Kerberos username [george]:

Kerberos password for george:

I just hit enter for both questions and then the program seems to continue
on with no problems. However I need this code to be automated through a cron
task and so I'd rather not having it pausing the program to ask me these two
questions. Is there something I'm not supplying it so that it won't ask
this? Something I need to do to stop it asking? Hopefully someone has some
ideas. Thanks.




Sincerely,
Ben May
Senior Research Analyst
Herbert Irving Comprehensive Cancer Center
212-851-4772
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to