Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

java - Java SSH客户端(如PuTTy)(Java SSH Client like PuTTy)

So, I want to create my own SSH Client, not just sending commands but a full on ssh client for me to use like you would use PuTTy or mobaxterm, can someone here point me in the right direction.

(因此,我想创建自己的SSH客户端,不仅发送命令,还提供完整的ssh客户端供我使用,就像您使用PuTTy或mobaxterm一样,这里有人可以向我指出正确的方向。)

Things I tried / thought of: - Using Jsch to send and execute commands (If its possible I would love to know if this is able to be done without using Jsch).

(我尝试过/想到的事情:-使用Jsch发送和执行命令(如果可能的话,我很想知道如果不使用Jsch就可以做到)。)

  ask by Aaron Akhtar translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

SSH is a protocol that is defined to run on top of TCP, and you can make TCP connections in java using the java.net.Socket class.

(SSH是一种定义为在TCP之上运行的协议,您可以使用java.net.Socket类在Java中建立TCP连接。)

So, yes, it can be done.

(因此,是的,可以做到。)

You'd have to implement the protocol yourself (or use JSch to do it, but given that all these tools already exist, and it's security, where in general relying on widely used tools is orders of magnitude more intelligent than relying on hand-written stuff, given that a security bug is very hard to test for – I assume this is some sort of exercise in sheer dogged arrogance, or, more likely, a learning exercise, which'd mean that you wouldn't want to use jsch here).

(您必须自己实现协议(或使用JSch来实现,但是鉴于所有这些工具已经存在,并且它是安全性),通常,广泛使用的工具比依赖手写的要聪明得多。的东西,因为一个安全漏洞是非常困难的测试-我想这是在纯粹的顽强傲慢某种运动,或者更可能的是,一个学习锻炼,which'd意味着你不会想在这里使用jsch )。)

ssh works by sending any number of streams across the network, encrypted.

(ssh通过在网络上发送任意数量的加密流来工作。)

By default, there is one stream (a two-way stream), with the user's shell being on one end (so, the /bin/bash executable, for example), and a terminal (where what you type forms the input, and any output is echoed to the terminal window) on the other.

(默认情况下,有一个流(双向流),用户的外壳位于一端(例如, /bin/bash可执行文件),而一个终端(由您输入的内容构成输入),以及任何输出都将回显到另一个终端窗口上。)

ssh does NOT wait for you type a command then run it;

(ssh不会等待您键入命令然后运行它;)

that's /bin/bash doing this.

(/bin/bash正在执行此操作。)

This is basic linux info and has no direct bearing on ssh (the protocol), that's just what you're used to, because sshd (the linux executable that forms an ssh server) by default hooks your terminal up to the target server's shell executable.

(这是基本的Linux信息,与ssh(协议)没有直接关系,这就是您所习惯的,因为sshd(构成ssh服务器的linux可执行文件)默认情况下会将您的终端挂接到目标服务器的shell可执行文件上。)

Usually bash.

(通常是bash。)

Given that you know nothing of this, this sounds like a project that's a bit too far fetched as a starter experiment, but I'm going by incomplete information to make this assessment.

(鉴于您对此一无所知,这听起来像一个项目,作为入门实验来说有些牵强,但是我要借助不完整的信息来进行此评估。)

I'd start by making a trivial telnet client and server.

(我将从制作一个简单的telnet客户端和服务器开始。)

telnet is at this point extremely outdated but it is basically ssh without the multiplexing of streams nor the encryption.

(telnet在这一点上已经过时了,但是它基本上是ssh,没有流的多路复用或加密。)

If you can't write a telnet client, you can't write an ssh client either.

(如果您不能编写telnet客户端,也不能编写ssh客户端。)

And you can still start telnet servers on linux machines for testing purposes.

(而且,您仍然可以在Linux机器上启动telnet服务器以进行测试。)

Once you've got that down, start figuring out the crypto and the multiplexing*.

(一旦发现问题,就开始弄清楚加密和多路复用*。)

*) With ssh you can, whilst having a shell open, also port forward and such;

(*)使用ssh,您可以在打开外壳的同时向前端口等;)

check out the -R and -L and -D options in standard ssh.

(查看标准ssh中的-R-L-D选项。)

Each such option allows for another stream to be sent along.

(每个这样的选项都允许发送另一个流。)

(whilst you're sending shell commands and seeing their results, at the same time, over the same ssh connection, you are, say, sending a print job to a printer in the network of the other machine).

((同时,您正在通过相同的ssh连接发送shell命令并查看其结果,也就是说,您正在将打印作业发送到另一台计算机的网络中的打印机)。)

Sending multiple streams through a single connection is called 'multiplexing', and it is part of the ssh specification.

(通过单个连接发送多个流称为“多路复用”,它是ssh规范的一部分。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...