我想编写一个具有两种连接类型的自定义SSH服务器的应用程序:
我在Java中这样做,我认为是正确的工具。我成功地编写了一些用于身份验证的代码(感谢在网络上找到的资源),并且可以在我的连接上运行/bin/sh,所以我想我已经安装好了。问题是,从现在开始,我被困住了,因为我不知道这些东西是如何工作的,米娜是如何具体地工作的。
基本上,我需要访问每个SSH连接的输入和输出流,然后我可以自己整理东西,买什么合适的方法来获得它呢?
我应该做一个定制频道吗?定制壳牌?一组自定义的命令?
有谁能告诉我有关这个问题的资料吗?
发布于 2012-10-09 13:23:21
我找到了解决办法:
首先,您必须实现一个命令工厂,如下所示:
class CommandFactory extends Factory[Command] {
override def create():Command = {
new Command() {
def destroy() {}
def setInputStream(in: InputStream) {}
def setErrorStream(err: OutputStream) {}
def setOutputStream(out: OutputStream) {}
def start(env: Environment) {}
def setExitCallback(callback: ExitCallback) {}
}
}
}然后像这样设置ssh服务器:
sshd.setShellFactory(new CommandFactory())当然,您可以扩展实现,将所需的任何内容传递给命令。
命令的实现是定义shell行为的地方。
发布于 2012-10-05 13:34:14
这是我对问题本身发表的评论的后续。
若要允许客户端(客户端)通过SSH直接或通过与服务器(网关)相同网络上的另一台计算机访问远程计算机(服务器)上的端口,只需使用-L标志即可。
直接从客户机到服务器(客户端机器上的端口8080将隧道到服务器上的80 ):
ssh -L 8080:localhost:80 server通过网关从客户机到服务器(客户端机器上的端口8080将隧道到服务器上的80 ):
ssh -L 8080:server:80 gateway在ssh的手册页中,下面是如何使用-L标志:
-L [bind_address:]port:host:hostport
Specifies that the given port on the local (client) host is to be
forwarded to the given host and port on the remote side. This
works by allocating a socket to listen to port on the local side,
optionally bound to the specified bind_address. Whenever a
connection is made to this port, the connection is forwarded over
the secure channel, and a connection is made to host port
hostport from the remote machine. Port forwardings can also be
specified in the configuration file. IPv6 addresses can be
specified by enclosing the address in square brackets. Only the
superuser can forward privileged ports. By default, the local
port is bound in accordance with the GatewayPorts setting.
However, an explicit bind_address may be used to bind the
connection to a specific address. The bind_address of
``localhost'' indicates that the listening port be bound for
local use only, while an empty address or `*' indicates that the
port should be available from all interfaces.https://stackoverflow.com/questions/12745539
复制相似问题