JAVA->SSH№ 1
Автор: Briska
Дата : 09-02-04, Пнд, 09:02:17

Dear All,

Anyways, I have run into little problem and wonder if you could help. Is there a sipmle way to connect to an SSHD from within a java application?

I am doing this secure tunneling project, and need to initialise this connection first.

I have used connections to smtp servers before in form of
new Socket(smtpserver, 25);
then got a new outputStream
and sent certain commands that the server was expexting like
out.print('HOSTU' )
....

.
.
Out.flush().

Something like that.
My guesses are that I need to open a connection to port 22 of the machine running sshd and then send certain commands using its outputStream.

I have been unable to find what exactly it is expecting?

Could you help please? Any ideas.

Ps I know that I am just barging in from across the atlantic but any help would be appreciated and properly acknoledged.
Thanks a lot.
.:: Briska ::.
Тот самый Бриска из далекого и туманного...
Профиль 

JAVA->SSH№ 2
Автор: Tarlog
Дата : 09-02-04, Пнд, 14:49:35

Профиль 

JAVA->SSH№ 3
Автор: Дядя Федор
Дата : 09-02-04, Пнд, 18:52:03

Мой вольный перевод...

Так или иначе, я столкнулся с небольшой проблемой, и надеюсь Вы могли бы мне помочь. Существует простой способ соединиться с SSHD из приложения java?

Я делаю этот проект безопасного туннелирования, и должен сначала инициализировать это подключение.

Я использовал подключения к smtp серверам прежде в форме
new Socket (smtpserver, 25);
Тогда получил новый outputStream
И послал несколько команд, которые ожидал сервер
Out.print ('HOSTU'
....

.
.
Out.flush ().

Что-то вроде этого.
Мои предположения состоят в том, что я должен открыть подключение к порту 22 на машине, выполняющей sshd и затем послать некоторые команды, использующие ее outputStream.

Я не смог найти, чего точно она ожидает?

Вы могли бы помочь пожалуйста? Любые идеи.

Ps я знаю, что я только мешаю врываясь из-за Атлантики, но любая справка была бы оценена и должным образом acknoledge.
Большое спасибо.

Не моя область, абсолютно... но всё-таки

/******************************************************************************
*
* Copyright (c) 1998,99 by Mindbright Technology AB, Stockholm, Sweden.
*                www.mindbright.se, info@mindbright.se
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*****************************************************************************
* $Author: mats $
* $Date: 1999/02/09 20:09:06 $
* $Name: rel0-98-4 $
*****************************************************************************/
package mindbright.application;

import java.io.*;

import java.awt.*;
import java.awt.event.*;

import mindbright.ssh.*;
import mindbright.security.*;
import mindbright.terminal.*;

public class MindTunnel {

public static void main(String[] argv) {
    MindTunnel controller = new MindTunnel();
    controller.startup(argv);
}

public void startup(String[] argv) {
    try {
      String hostKeyFile    = null;
      String authKeysDir    = null;
      boolean haveGUI       = true;
      boolean doGenerateId   = false;
      int    port          = SSH.DEFAULTPORT;
      int    bits          = SSH.SERVER_KEY_LENGTH;
      int    i;

      for(i = 0; i < argv.length; i++) {
String arg = argv;
if(arg.charAt(0) != '-' )
break;
switch(arg.charAt(1)) {
case 'a':
authKeysDir = argv[i++] + File.separatorChar;
break;
case 'b':
bits = Integer.parseInt(argv[++i]);
break;
case 'g':
doGenerateId = true;
break;
case 'd':
haveGUI = false;
break;
case 'v':
System.out.println("verbose mode selected..." );
SSH.DEBUG = true;
break;
case 'V':
System.out.println("SSH version " + SSH.VER_SSH + ", protocol version " +
    SSH.VER_MAJOR + "." + SSH.VER_MINOR);
System.exit(0);
break;
case 'p':
port = Integer.parseInt(argv[++i]);
break;
default:
throw new Exception();
}
      }

      if(doGenerateId) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String fileName, passwd, comment;
System.out.print("filename: " );
fileName = br.readLine();
System.out.print("password: " );
passwd = br.readLine();
System.out.print("comment: " );
comment = br.readLine();
System.out.print("Generating identity of length " + bits + "..." );
KeyPair kp = SSH.generateRSAKeyPair(bits);
System.out.println("done" );
   
SSH.generateKeyFiles(kp, fileName, passwd, comment);
System.exit(0);
      }

      hostKeyFile = argv;

      if(authKeysDir == null) {
i = hostKeyFile.lastIndexOf(File.separatorChar);
if(i != -1)
authKeysDir = hostKeyFile.substring(0, i + 1);
else
authKeysDir = "";
      }

      SSHServer.setAuthKeysDir(authKeysDir);
      SSHServer.setHostKeyFile(hostKeyFile);

      SSHServer.sshd(port);

    } catch(IOException e) {
      System.out.println("Error starting MindTunnel sshd: " + e);
    } catch(Exception e) {
      System.out.println("usage: MindTunnel [options] <host_key_file>" );
      System.out.println("Options:" );
      System.out.println(" -a <dir> Directory where the users authorized_keys files are located (default" );
      System.out.println("            same dir as host-key)." );
      System.out.println(" -b <bits> Specifies the number of bits in the server key (default 768)." );
      System.out.println(" -g       Generate authentication key pair files (private and public)." );
      System.out.println(" -d       No terminal-window, activities are logged to stdout." );
      System.out.println(" -v       Verbose; display verbose debugging messages." );
      System.out.println(" -V       Display version number only." );
      System.out.println(" -p <port> Port to listen for connections on (default is 22)." );
    }

    System.exit(0);
}


}


[ 10-02-04, Tue, 2:04:18 Отредактировано: Дядя Федор ]
Профиль 

JAVA->SSH№ 4
Автор: Briska
Дата : 14-02-04, Сбт, 13:34:08

Спасибо люди!
я умудрился сделать это сам.

я нашел такую интересную пенку.. называется jsh это pure ssh implementation in java.

works lovely. About the midterm.. its too large a prgject to understand who it works.
and the fiben guy used it in his project -> he had imported some of the libraries from there.

PS.Дядя Федор мне понравлся твой перевод на русский но сказать честно я даже таких терминов то и не знаю на русском... вот что полычается когда обучение проушодит на иносранном языке
ПС Тёмкин транслит это гениальная штука, однажду привикнув к неи !

и на последок, я даже и не помню как так полычилось что я написал что я из-за атлантики совсем нет...
я тот самый Бриска.....
Тот самый Бриска из далекого и туманного...
Профиль 


Вы не зарегистрированы либо не вошли в портал!!!
Регистрация или вход в портал - в главном меню.



 Просмотров:   001862    Постингов:   000004