Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SFTP connection through Java asking for weird authentication

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 here 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.

like image 383
cardician Avatar asked Jun 04 '12 13:06

cardician


1 Answers

Thought I'd post an answer here since in case anyone else ends up running into a similar issue. Turns out I am missing a piece of code that makes all the difference. I just needed to add

session.setConfig("PreferredAuthentications",                    "publickey,keyboard-interactive,password"); 

before

session.connect(); 

and everything works perfectly now.

like image 99
cardician Avatar answered Sep 23 '22 09:09

cardician