简体   繁体   中英

JSch Session Connecting

Hi I am trying to connect via ssh tunneling to a database on a server, but I can't even get the Jsch session to connect. I am attempting to do this in GWT as part of my back-end code. So this is in the Implementation part of the server side code. I am not that familiar with servers in general. Typically in terminal I type:

ssh -x username@xxxxx.xxx.edu

Then I am prompted for my password and I enter the password and then I am in.

So in java my code is as follows:

String host="xxxxx.xxx.edu";

String user="username";
String password="password";

Session session= null;
try{
            //Set StrictHostKeyChecking property to no to avoid UnknownHostKey issue
            java.util.Properties config = new java.util.Properties();
            config.put("StrictHostKeyChecking", "no");
            JSch jsch = new JSch();
            session=jsch.getSession(user, host, 22);
            session.setPassword(password);
            session.setConfig(config);
            session.connect();
}

I've double checked the username and the password and the host string and they are all what I use in terminal successfully.

The error I get on the 'session.connect()' line is as follows: (scroll right to see whole error)

com.jcraft.jsch.JSchException: java.security.AccessControlException: access denied (java.net.SocketPermission xxxxx.xxx.edu resolve)
at com.jcraft.jsch.Util.createSocket(Util.java:341)
at com.jcraft.jsch.Session.connect(Session.java:194)
at com.jcraft.jsch.Session.connect(Session.java:162)
at com.front.server.GameServiceImpl.createGame(GameServiceImpl.java:39)

Is there something I am missing? Is this not identical to what I do in terminal to sign in via ssh? I have also tried prepending 'ssh://' to the host string as well but to no avail.

Thanks in advance!

I figured out that there is no problem with the code above. I copied/pasted it into a simple java main and it worked fine. It appears there is something wrong with putting that same code in GWT back-end.

According to the exception message, it seems that the problem has not come from JSch.

Refer to Security and Permissions on java.sun.com:

All applets and any applications invoked with a security manager must be granted explicit permission to access local system resources apart from read access to the directory and its subdirectories where the program is invoked. The Java platform provides permissions to allow various levels of access to different types of local information.

,and see SocketPermission section.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM