Re: Apache MINA SSHd default ShellFactory Chocked the resources

2017-03-08 Thread elijah baley
Sorry, e-mail is not suitable for debugging - Eclipse/Intellij/NetBeans are...



From: waseem.farooqui <waseem.farooqu...@gmail.com>
Sent: Wednesday, March 8, 2017 8:05 AM
To: dev@mina.apache.org
Subject: Re: Apache MINA SSHd default ShellFactory Chocked the resources

I am running this code.
And change this
public boolean authenticate(String username, String password,
ServerSession session) {
   return (GenericUtils.length(username) > 0) &&
username.equals(password);
}
by this

public boolean authenticate(String username, String password,
ServerSession session) {
return true;
}


public static void main(String[] args) throws Exception {
int port = 8000;
String provider;
boolean error = false;
String hostKeyType =
AbstractGeneratorHostKeyProvider.DEFAULT_ALGORITHM;
Map<String, String> options = new LinkedHashMap<>();

int numArgs = GenericUtils.length(args);
for (int i = 0; i < numArgs; i++) {
String argName = args[i];
if ("-p".equals(argName)) {
if (i + 1 >= numArgs) {
System.err.println("option requires an argument: " +
argName);
break;
}
port = Integer.parseInt(args[++i]);
} else if ("-key-type".equals(argName)) {
if (i + 1 >= numArgs) {
System.err.println("option requires an argument: " +
argName);
break;
}
hostKeyType = args[++i].toUpperCase();
} else if ("-io".equals(argName)) {
if (i + 1 >= numArgs) {
System.err.println("option requires an argument: " +
argName);
break;
}
provider = args[++i];
if ("mina".equals(provider)) {
System.setProperty(IoServiceFactory.class.getName(),
MinaServiceFactory.class.getName());
} else if ("nio2".endsWith(provider)) {
System.setProperty(IoServiceFactory.class.getName(),
Nio2ServiceFactory.class.getName());
} else {
System.err.println("provider should be mina or nio2: " +
argName);
break;
}
} else if ("-o".equals(argName)) {
if (i + 1 >= numArgs) {
System.err.println("option requires and argument: " +
argName);
error = true;
break;
}
String opt = args[++i];
int idx = opt.indexOf('=');
if (idx <= 0) {
System.err.println("bad syntax for option: " + opt);
error = true;
break;
}
options.put(opt.substring(0, idx), opt.substring(idx + 1));
} else if (argName.startsWith("-")) {
System.err.println("illegal option: " + argName);
error = true;
break;
} else {
System.err.println("extra argument: " + argName);
error = true;
break;
}
}
if (error) {
System.err.println("usage: sshd [-p port] [-io mina|nio2]
[-key-type RSA|DSA|EC] [-o option=value]");
System.exit(-1);
}

System.err.println("Starting SSHD on port " + port);

SshServer sshd = SshServer.setUpDefaultServer();
Map<String, Object> props = sshd.getProperties();
props.putAll(options);
setupServerBanner(sshd, options);
sshd.setPort(port);

AbstractGeneratorHostKeyProvider hostKeyProvider;
Path hostKeyFile;
if (SecurityUtils.isBouncyCastleRegistered()) {
hostKeyFile = new File("key.pem").toPath();
hostKeyProvider =
SecurityUtils.createGeneratorHostKeyProvider(hostKeyFile);
} else {
hostKeyFile = new File("key.ser").toPath();
hostKeyProvider = new
SimpleGeneratorHostKeyProvider(hostKeyFile);
}
hostKeyProvider.setAlgorithm(hostKeyType);

List keys =
ValidateUtils.checkNotNullAndNotEmpty(hostKeyProvider.loadKeys(),
"Failed to load keys from %s", hostKeyFile);
KeyPair kp = keys.get(0);
PublicKey pubKey = kp.getPublic();
String keyAlgorithm = pubKey.getAlgorithm();
// force re-generation of host key if not same algorithm
if (!Objects.equals(keyAlgorithm, hostKeyProvider.getAlgorithm())) {
Files.deleteIfExists(hos

Re: Apache MINA SSHd default ShellFactory Chocked the resources

2017-03-07 Thread waseem.farooqui
I am running this code.
And change this 
public boolean authenticate(String username, String password,
ServerSession session) {
   return (GenericUtils.length(username) > 0) &&
username.equals(password);
}
by this 

public boolean authenticate(String username, String password,
ServerSession session) {
return true;
}


public static void main(String[] args) throws Exception {
int port = 8000;
String provider;
boolean error = false;
String hostKeyType =
AbstractGeneratorHostKeyProvider.DEFAULT_ALGORITHM;
Map options = new LinkedHashMap<>();

int numArgs = GenericUtils.length(args);
for (int i = 0; i < numArgs; i++) {
String argName = args[i];
if ("-p".equals(argName)) {
if (i + 1 >= numArgs) {
System.err.println("option requires an argument: " +
argName);
break;
}
port = Integer.parseInt(args[++i]);
} else if ("-key-type".equals(argName)) {
if (i + 1 >= numArgs) {
System.err.println("option requires an argument: " +
argName);
break;
}
hostKeyType = args[++i].toUpperCase();
} else if ("-io".equals(argName)) {
if (i + 1 >= numArgs) {
System.err.println("option requires an argument: " +
argName);
break;
}
provider = args[++i];
if ("mina".equals(provider)) {
System.setProperty(IoServiceFactory.class.getName(),
MinaServiceFactory.class.getName());
} else if ("nio2".endsWith(provider)) {
System.setProperty(IoServiceFactory.class.getName(),
Nio2ServiceFactory.class.getName());
} else {
System.err.println("provider should be mina or nio2: " +
argName);
break;
}
} else if ("-o".equals(argName)) {
if (i + 1 >= numArgs) {
System.err.println("option requires and argument: " +
argName);
error = true;
break;
}
String opt = args[++i];
int idx = opt.indexOf('=');
if (idx <= 0) {
System.err.println("bad syntax for option: " + opt);
error = true;
break;
}
options.put(opt.substring(0, idx), opt.substring(idx + 1));
} else if (argName.startsWith("-")) {
System.err.println("illegal option: " + argName);
error = true;
break;
} else {
System.err.println("extra argument: " + argName);
error = true;
break;
}
}
if (error) {
System.err.println("usage: sshd [-p port] [-io mina|nio2]
[-key-type RSA|DSA|EC] [-o option=value]");
System.exit(-1);
}

System.err.println("Starting SSHD on port " + port);

SshServer sshd = SshServer.setUpDefaultServer();
Map props = sshd.getProperties();
props.putAll(options);
setupServerBanner(sshd, options);
sshd.setPort(port);

AbstractGeneratorHostKeyProvider hostKeyProvider;
Path hostKeyFile;
if (SecurityUtils.isBouncyCastleRegistered()) {
hostKeyFile = new File("key.pem").toPath();
hostKeyProvider =
SecurityUtils.createGeneratorHostKeyProvider(hostKeyFile);
} else {
hostKeyFile = new File("key.ser").toPath();
hostKeyProvider = new
SimpleGeneratorHostKeyProvider(hostKeyFile);
}
hostKeyProvider.setAlgorithm(hostKeyType);

List keys =
ValidateUtils.checkNotNullAndNotEmpty(hostKeyProvider.loadKeys(),
"Failed to load keys from %s", hostKeyFile);
KeyPair kp = keys.get(0);
PublicKey pubKey = kp.getPublic();
String keyAlgorithm = pubKey.getAlgorithm();
// force re-generation of host key if not same algorithm
if (!Objects.equals(keyAlgorithm, hostKeyProvider.getAlgorithm())) {
Files.deleteIfExists(hostKeyFile);
hostKeyProvider.clearLoadedKeys();
}
sshd.setKeyPairProvider(hostKeyProvider);

sshd.setShellFactory(InteractiveProcessShellFactory.INSTANCE);
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password,
ServerSession session) {
return true;
//return (GenericUtils.length(username) > 0) &&
username.equals(password);
}
});
   

Re: Apache MINA SSHd default ShellFactory Chocked the resources

2017-03-07 Thread Guillaume Nodet
I agree, the informations given are not sufficient.  I ran the server code
and connected with 2 different clients without any problems.

2017-03-07 18:04 GMT+01:00 elijah baley <e_ba...@outlook.com>:

> You are doing something wrong (just what - is difficult to say) - if you
> run the code in SshServer#main you can connect several clients - I did it -
> connected both PUTTY and Ubuntu SSH client to a server running
> SshServer#main. All that remains is now for you to compare your code with
> the one that runs and then debug your code to see why it is not the same as
> the built-in.
>
> 
> From: waseem.farooqui <waseem.farooqu...@gmail.com>
> Sent: Tuesday, March 7, 2017 1:25 PM
> To: dev@mina.apache.org
> Subject: Re: Apache MINA SSHd default ShellFactory Chocked the resources
>
> I run the SshServer code in the link u shared  but got the same result. Its
> because ProcessShellFactory spawns a single thread which is apparently
> shared among all the clients.
>
> Look what I did, I open 2 terminals and connect with the server from
> terminal 1.
> <http://apache-mina.10907.n7.nabble.com/file/n52377/
> Screenshot_from_2017-03-07_15-59-25.png>
>
> Everything works fine  I was able to enter any command.
> <http://apache-mina.10907.n7.nabble.com/file/n52377/
> Screenshot_from_2017-03-07_15-59-25.png>
>
> But when I login with the terminal 2, I was able to login but wouldn't get
> the shell because it was in use by terminal 1.
>
> <http://apache-mina.10907.n7.nabble.com/file/n52377/
> Screenshot_from_2017-03-07_15-59-50.png>
>
> Then I exit the terminal 1, so all the commands I entered at terminal 2 got
> executed when terminal 1 freed the shell.
>
> <http://apache-mina.10907.n7.nabble.com/file/n52377/
> Screenshot_from_2017-03-07_16-00-19.png>
>
> After it I was able to type any command.
>
> <http://apache-mina.10907.n7.nabble.com/file/n52377/
> Screenshot_from_2017-03-07_16-00-27.png>
>
> I want both clients to get the shell Simultaneously/parallel ? How could I
> achieve this ? Am I doing something wrong ?
>
>
>
>
>
>
>
> --
> View this message in context: http://apache-mina.10907.n7.
> nabble.com/Apache-MINA-SSHd-default-ShellFactory-Chocked-
> the-resources-tp52309p52377.html
> Apache MINA Developer Forum - Apache MINA SSHd default ShellFactory
> Chocked the resources<http://apache-mina.10907.n7.nabble.com/Apache-
> MINA-SSHd-default-ShellFactory-Chocked-the-resources-tp52309p52377.html>
> apache-mina.10907.n7.nabble.com
> Apache MINA SSHd default ShellFactory Chocked the resources. Hi Devs, I am
> using Apache MINA server for the ssh server implementation. I basically
> want to intercept all the commands typed by the...
>
>
>
> Sent from the Apache MINA Developer Forum mailing list archive at
> Nabble.com.
>
> [http://apache-mina.10907.n7.nabble.com/file/n52377/
> Screenshot_from_2017-03-07_15-59-25.png]
>
> [http://apache-mina.10907.n7.nabble.com/file/n52377/
> Screenshot_from_2017-03-07_15-59-25.png]
>
> [http://apache-mina.10907.n7.nabble.com/file/n52377/
> Screenshot_from_2017-03-07_15-59-50.png]
>
> [http://apache-mina.10907.n7.nabble.com/file/n52377/
> Screenshot_from_2017-03-07_16-00-19.png]
>
> [http://apache-mina.10907.n7.nabble.com/file/n52377/
> Screenshot_from_2017-03-07_16-00-27.png]
>



-- 

Guillaume Nodet


Re: Apache MINA SSHd default ShellFactory Chocked the resources

2017-03-07 Thread elijah baley
You are doing something wrong (just what - is difficult to say) - if you run 
the code in SshServer#main you can connect several clients - I did it - 
connected both PUTTY and Ubuntu SSH client to a server running SshServer#main. 
All that remains is now for you to compare your code with the one that runs and 
then debug your code to see why it is not the same as the built-in.


From: waseem.farooqui <waseem.farooqu...@gmail.com>
Sent: Tuesday, March 7, 2017 1:25 PM
To: dev@mina.apache.org
Subject: Re: Apache MINA SSHd default ShellFactory Chocked the resources

I run the SshServer code in the link u shared  but got the same result. Its
because ProcessShellFactory spawns a single thread which is apparently
shared among all the clients.

Look what I did, I open 2 terminals and connect with the server from
terminal 1.
<http://apache-mina.10907.n7.nabble.com/file/n52377/Screenshot_from_2017-03-07_15-59-25.png>

Everything works fine  I was able to enter any command.
<http://apache-mina.10907.n7.nabble.com/file/n52377/Screenshot_from_2017-03-07_15-59-25.png>

But when I login with the terminal 2, I was able to login but wouldn't get
the shell because it was in use by terminal 1.

<http://apache-mina.10907.n7.nabble.com/file/n52377/Screenshot_from_2017-03-07_15-59-50.png>

Then I exit the terminal 1, so all the commands I entered at terminal 2 got
executed when terminal 1 freed the shell.

<http://apache-mina.10907.n7.nabble.com/file/n52377/Screenshot_from_2017-03-07_16-00-19.png>

After it I was able to type any command.

<http://apache-mina.10907.n7.nabble.com/file/n52377/Screenshot_from_2017-03-07_16-00-27.png>

I want both clients to get the shell Simultaneously/parallel ? How could I
achieve this ? Am I doing something wrong ?







--
View this message in context: 
http://apache-mina.10907.n7.nabble.com/Apache-MINA-SSHd-default-ShellFactory-Chocked-the-resources-tp52309p52377.html
Apache MINA Developer Forum - Apache MINA SSHd default ShellFactory Chocked the 
resources<http://apache-mina.10907.n7.nabble.com/Apache-MINA-SSHd-default-ShellFactory-Chocked-the-resources-tp52309p52377.html>
apache-mina.10907.n7.nabble.com
Apache MINA SSHd default ShellFactory Chocked the resources. Hi Devs, I am 
using Apache MINA server for the ssh server implementation. I basically want to 
intercept all the commands typed by the...



Sent from the Apache MINA Developer Forum mailing list archive at Nabble.com.

[http://apache-mina.10907.n7.nabble.com/file/n52377/Screenshot_from_2017-03-07_15-59-25.png]

[http://apache-mina.10907.n7.nabble.com/file/n52377/Screenshot_from_2017-03-07_15-59-25.png]

[http://apache-mina.10907.n7.nabble.com/file/n52377/Screenshot_from_2017-03-07_15-59-50.png]

[http://apache-mina.10907.n7.nabble.com/file/n52377/Screenshot_from_2017-03-07_16-00-19.png]

[http://apache-mina.10907.n7.nabble.com/file/n52377/Screenshot_from_2017-03-07_16-00-27.png]


Re: Apache MINA SSHd default ShellFactory Chocked the resources

2017-03-07 Thread elijah baley
Basically the main method of SshServer does all this. It can be run as a 
standalone server and see that multiple clients can connect to it concurrently



From: Guillaume Nodet <gno...@apache.org>
Sent: Tuesday, March 7, 2017 10:59 AM
To: dev@mina.apache.org
Subject: Re: Apache MINA SSHd default ShellFactory Chocked the resources

The ProcessShellFactory already spawns a thread.
Here is the SshServer code which works with multiple clients:

https://github.com/apache/mina-sshd/blob/master/sshd-core/src/main/java/org/apache/sshd/server/SshServer.java#L465-L591
[https://avatars1.githubusercontent.com/u/47359?v=3=400]<https://github.com/apache/mina-sshd/blob/master/sshd-core/src/main/java/org/apache/sshd/server/SshServer.java#L465-L591>

mina-sshd/SshServer.java at master · apache/mina-sshd · 
GitHub<https://github.com/apache/mina-sshd/blob/master/sshd-core/src/main/java/org/apache/sshd/server/SshServer.java#L465-L591>
github.com
mina-sshd - Mirror of Apache MINA SSHD ... Skip to content




2017-03-06 9:54 GMT+01:00 waseem.farooqui <waseem.farooqu...@gmail.com>:

> You're right about the server being singleton, but my problem is with the
> ShellFactory. I used the recommended code found  here
> <https://mina.apache.org/sshd-project/embedding_ssh.html>  , and it's
Embedding SSHD in 5 minutes — Apache 
MINA<https://mina.apache.org/sshd-project/embedding_ssh.html>
mina.apache.org
Embedding SSHD in 5 minutes¶ SSHD is designed to be easily embedded in your 
application as an SSH server. SSH Server needs to be configured before it can 
be started.



> giving
> me the same problem. It basically only caters to one client at a time. If
> multiple clients connect at the same time, it only responds to the first
> one
> that connected. After the first one disconnects, it provides the shell to
> the other client. I want them to be provided the shell simultaneously. I
> get
> the same results using the InteractiveShellFactory.INSTANCE as with the
> /bin/sh command.
>
> From what I read  here
> <https://github.com/apache/mina-sshd#remote-command-execution>  , it says
[https://avatars1.githubusercontent.com/u/47359?v=3=400]<https://github.com/apache/mina-sshd#remote-command-execution>

apache/mina-sshd<https://github.com/apache/mina-sshd#remote-command-execution>
github.com
mina-sshd - Mirror of Apache MINA SSHD



> that you need to spawn threads for each command or each shell but how am I
> supposed to do that when I want each user to get a separate shell.
>
>
>
>
>
> --
> View this message in context: http://apache-mina.10907.n7.
> nabble.com/Apache-MINA-SSHd-default-ShellFactory-Chocked-
> the-resources-tp52309p52370.html
> Sent from the Apache MINA Developer Forum mailing list archive at
> Nabble.com.
>



--

Guillaume Nodet


Re: Apache MINA SSHd default ShellFactory Chocked the resources

2017-03-07 Thread waseem.farooqui
I run the SshServer code in the link u shared  but got the same result. Its
because ProcessShellFactory spawns a single thread which is apparently
shared among all the clients.

Look what I did, I open 2 terminals and connect with the server from
terminal 1.

 
 
Everything works fine  I was able to enter any command.

 

But when I login with the terminal 2, I was able to login but wouldn't get
the shell because it was in use by terminal 1.


 

Then I exit the terminal 1, so all the commands I entered at terminal 2 got
executed when terminal 1 freed the shell.


 

After it I was able to type any command.


 

I want both clients to get the shell Simultaneously/parallel ? How could I
achieve this ? Am I doing something wrong ?







--
View this message in context: 
http://apache-mina.10907.n7.nabble.com/Apache-MINA-SSHd-default-ShellFactory-Chocked-the-resources-tp52309p52377.html
Sent from the Apache MINA Developer Forum mailing list archive at Nabble.com.


Re: Apache MINA SSHd default ShellFactory Chocked the resources

2017-03-07 Thread Guillaume Nodet
The ProcessShellFactory already spawns a thread.
Here is the SshServer code which works with multiple clients:

https://github.com/apache/mina-sshd/blob/master/sshd-core/src/main/java/org/apache/sshd/server/SshServer.java#L465-L591

2017-03-06 9:54 GMT+01:00 waseem.farooqui :

> You're right about the server being singleton, but my problem is with the
> ShellFactory. I used the recommended code found  here
>   , and it's
> giving
> me the same problem. It basically only caters to one client at a time. If
> multiple clients connect at the same time, it only responds to the first
> one
> that connected. After the first one disconnects, it provides the shell to
> the other client. I want them to be provided the shell simultaneously. I
> get
> the same results using the InteractiveShellFactory.INSTANCE as with the
> /bin/sh command.
>
> From what I read  here
>   , it says
> that you need to spawn threads for each command or each shell but how am I
> supposed to do that when I want each user to get a separate shell.
>
>
>
>
>
> --
> View this message in context: http://apache-mina.10907.n7.
> nabble.com/Apache-MINA-SSHd-default-ShellFactory-Chocked-
> the-resources-tp52309p52370.html
> Sent from the Apache MINA Developer Forum mailing list archive at
> Nabble.com.
>



-- 

Guillaume Nodet


Re: Apache MINA SSHd default ShellFactory Chocked the resources

2017-03-06 Thread elijah baley
It seems that you are doing something wrong - e.g., not spawning a new thread 
for each shell, or using some kind of mutual exclusion mechanism, or using a 
single threaded thread "pool" - the possibilities are endless. AFAIK the code 
supports multiple concurrent shell sessions - I doubt something so basic has 
not been already attempted and someone would have raised this issue long ago 
(around version 0.9). Perhaps someone in the dev. community can post code 
he/she has already written that does this...


From: waseem.farooqui <waseem.farooqu...@gmail.com>
Sent: Monday, March 6, 2017 10:54 AM
To: dev@mina.apache.org
Subject: Re: Apache MINA SSHd default ShellFactory Chocked the resources

You're right about the server being singleton, but my problem is with the
ShellFactory. I used the recommended code found  here
<https://mina.apache.org/sshd-project/embedding_ssh.html>  , and it's giving
Embedding SSHD in 5 minutes — Apache 
MINA<https://mina.apache.org/sshd-project/embedding_ssh.html>
mina.apache.org
Embedding SSHD in 5 minutes¶ SSHD is designed to be easily embedded in your 
application as an SSH server. SSH Server needs to be configured before it can 
be started.



me the same problem. It basically only caters to one client at a time. If
multiple clients connect at the same time, it only responds to the first one
that connected. After the first one disconnects, it provides the shell to
the other client. I want them to be provided the shell simultaneously. I get
the same results using the InteractiveShellFactory.INSTANCE as with the
/bin/sh command.

>From what I read  here
<https://github.com/apache/mina-sshd#remote-command-execution>  , it says
[https://avatars1.githubusercontent.com/u/47359?v=3=400]<https://github.com/apache/mina-sshd#remote-command-execution>

apache/mina-sshd<https://github.com/apache/mina-sshd#remote-command-execution>
github.com
mina-sshd - Mirror of Apache MINA SSHD



that you need to spawn threads for each command or each shell but how am I
supposed to do that when I want each user to get a separate shell.





--
View this message in context: 
http://apache-mina.10907.n7.nabble.com/Apache-MINA-SSHd-default-ShellFactory-Chocked-the-resources-tp52309p52370.html
Apache MINA Developer Forum - Apache MINA SSHd default ShellFactory Chocked the 
resources<http://apache-mina.10907.n7.nabble.com/Apache-MINA-SSHd-default-ShellFactory-Chocked-the-resources-tp52309p52370.html>
apache-mina.10907.n7.nabble.com
Apache MINA SSHd default ShellFactory Chocked the resources. Hi Devs, I am 
using Apache MINA server for the ssh server implementation. I basically want to 
intercept all the commands typed by the...



Sent from the Apache MINA Developer Forum mailing list archive at Nabble.com.


Re: Apache MINA SSHd default ShellFactory Chocked the resources

2017-03-06 Thread waseem.farooqui
You're right about the server being singleton, but my problem is with the
ShellFactory. I used the recommended code found  here
  , and it's giving
me the same problem. It basically only caters to one client at a time. If
multiple clients connect at the same time, it only responds to the first one
that connected. After the first one disconnects, it provides the shell to
the other client. I want them to be provided the shell simultaneously. I get
the same results using the InteractiveShellFactory.INSTANCE as with the 
/bin/sh command.

>From what I read  here
  , it says
that you need to spawn threads for each command or each shell but how am I
supposed to do that when I want each user to get a separate shell.





--
View this message in context: 
http://apache-mina.10907.n7.nabble.com/Apache-MINA-SSHd-default-ShellFactory-Chocked-the-resources-tp52309p52370.html
Sent from the Apache MINA Developer Forum mailing list archive at Nabble.com.


Re: Apache MINA SSHd default ShellFactory Chocked the resources

2017-03-02 Thread elijah baley

Seems like the wrong way - the SSHDServer is a singleton and should be created 
only once (!). Please read the documentation on the MINA side about how to set 
up a server and how to configure command/shell factories.


From: waseem.farooqui <waseem.farooqu...@gmail.com>
Sent: Thursday, March 2, 2017 12:53 PM
To: dev@mina.apache.org
Subject: Re: Apache MINA SSHd default ShellFactory Chocked the resources

How do you do that ?
I am connecting multiple client with the servers i-e I open 2 terminals and
ssh the server with both of them.
I open a new thread at every new connection like this

public static void main(String[] args) {

new Thread(new SshDaemon()).start();
}

@Override
public void run() {

SshServer sshd = SshServer.setUpDefaultServer();
//creating the welcome banner for after login
PropertyResolverUtils.updateProperty(
sshd,
ServerFactoryManager.WELCOME_BANNER,
BANNER);

sshd.setFileSystemFactory(new
VirtualFileSystemFactory(Paths.get(System.getProperty("user.dir";


//adding the password authenticator
sshd.setPasswordAuthenticator(
new SshPasswordAuthenticator());

//setting the port the ssh daemon is listening on
sshd.setPort(PORT);
sshd.setHost("0.0.0.0");
//setting the class that hooks up users
//with their session
//sshd.setShellFactory( new SshSessionFactory() );



sshd.setSubsystemFactories(Collections.<NamedFactoryCommand>>singletonList(new
SftpSubsystemFactory()));
sshd.setShellFactory(new ProcessShellFactory(new String[]{"/bin/sh",
"-i", "-l"}));


sshd.setKeyPairProvider(
new SimpleGeneratorHostKeyProvider(
new File("id_rsa")));

try {
sshd.start();
} catch (IOException e) {
e.printStackTrace();
}

//TODO replace with proper interrupt
while (!shutdownRequested) {
try {
Thread.sleep(500);
} catch (Exception e) {
}
}
}

`sshd.setShellFactory(new ProcessShellFactory(new String[]{"/bin/sh", "-i",
"-l"}));` I am using this shell.
Its default and built-in I guess, will you please explain me with the code
How to use this `InteractiveProcessShellFactory`.



--
View this message in context: 
http://apache-mina.10907.n7.nabble.com/Apache-MINA-SSHd-default-ShellFactory-Chocked-the-resources-tp52309p52318.html
Apache MINA Developer Forum - Apache MINA SSHd default ShellFactory Chocked the 
resources<http://apache-mina.10907.n7.nabble.com/Apache-MINA-SSHd-default-ShellFactory-Chocked-the-resources-tp52309p52318.html>
apache-mina.10907.n7.nabble.com
Apache MINA SSHd default ShellFactory Chocked the resources. Hi Devs, I am 
using Apache MINA server for the ssh server implementation. I basically want to 
intercept all the commands typed by the...



Sent from the Apache MINA Developer Forum mailing list archive at Nabble.com.


Re: Apache MINA SSHd default ShellFactory Chocked the resources

2017-03-02 Thread waseem.farooqui
/How do you do that ? /
I am connecting multiple client with the servers i-e I open 2 terminals and
ssh the server with both of them.
I open a new thread at every new connection like this

public static void main(String[] args) {

new Thread(new SshDaemon()).start();
}

@Override
public void run() {

SshServer sshd = SshServer.setUpDefaultServer();
//creating the welcome banner for after login
PropertyResolverUtils.updateProperty(
sshd,
ServerFactoryManager.WELCOME_BANNER,
BANNER);

sshd.setFileSystemFactory(new
VirtualFileSystemFactory(Paths.get(System.getProperty("user.dir";


//adding the password authenticator
sshd.setPasswordAuthenticator(
new SshPasswordAuthenticator());

//setting the port the ssh daemon is listening on
sshd.setPort(PORT);
sshd.setHost("0.0.0.0");
//setting the class that hooks up users
//with their session
//sshd.setShellFactory( new SshSessionFactory() );


   
sshd.setSubsystemFactories(Collections.>singletonList(new
SftpSubsystemFactory()));
sshd.setShellFactory(new ProcessShellFactory(new String[]{"/bin/sh",
"-i", "-l"}));


sshd.setKeyPairProvider(
new SimpleGeneratorHostKeyProvider(
new File("id_rsa")));

try {
sshd.start();
} catch (IOException e) {
e.printStackTrace();
}

//TODO replace with proper interrupt
while (!shutdownRequested) {
try {
Thread.sleep(500);
} catch (Exception e) {
}
}
}

`sshd.setShellFactory(new ProcessShellFactory(new String[]{"/bin/sh", "-i",
"-l"}));` I am using this shell.
Its default and built-in I guess, will you please explain me with the code
How to use this `InteractiveProcessShellFactory`.



--
View this message in context: 
http://apache-mina.10907.n7.nabble.com/Apache-MINA-SSHd-default-ShellFactory-Chocked-the-resources-tp52309p52317.html
Sent from the Apache MINA Developer Forum mailing list archive at Nabble.com.


Re: Apache MINA SSHd default ShellFactory Chocked the resources

2017-03-02 Thread waseem.farooqui
How do you do that ? 
I am connecting multiple client with the servers i-e I open 2 terminals and
ssh the server with both of them. 
I open a new thread at every new connection like this 

public static void main(String[] args) { 

new Thread(new SshDaemon()).start(); 
} 

@Override 
public void run() { 

SshServer sshd = SshServer.setUpDefaultServer(); 
//creating the welcome banner for after login 
PropertyResolverUtils.updateProperty( 
sshd, 
ServerFactoryManager.WELCOME_BANNER, 
BANNER); 

sshd.setFileSystemFactory(new
VirtualFileSystemFactory(Paths.get(System.getProperty("user.dir"; 


//adding the password authenticator 
sshd.setPasswordAuthenticator( 
new SshPasswordAuthenticator()); 

//setting the port the ssh daemon is listening on 
sshd.setPort(PORT); 
sshd.setHost("0.0.0.0"); 
//setting the class that hooks up users 
//with their session 
//sshd.setShellFactory( new SshSessionFactory() ); 


   
sshd.setSubsystemFactories(Collections.>singletonList(new
SftpSubsystemFactory())); 
sshd.setShellFactory(new ProcessShellFactory(new String[]{"/bin/sh",
"-i", "-l"})); 


sshd.setKeyPairProvider( 
new SimpleGeneratorHostKeyProvider( 
new File("id_rsa"))); 

try { 
sshd.start(); 
} catch (IOException e) { 
e.printStackTrace(); 
} 

//TODO replace with proper interrupt 
while (!shutdownRequested) { 
try { 
Thread.sleep(500); 
} catch (Exception e) { 
} 
} 
} 

`sshd.setShellFactory(new ProcessShellFactory(new String[]{"/bin/sh", "-i",
"-l"}));` I am using this shell. 
Its default and built-in I guess, will you please explain me with the code
How to use this `InteractiveProcessShellFactory`.



--
View this message in context: 
http://apache-mina.10907.n7.nabble.com/Apache-MINA-SSHd-default-ShellFactory-Chocked-the-resources-tp52309p52318.html
Sent from the Apache MINA Developer Forum mailing list archive at Nabble.com.


Re: Apache MINA SSHd default ShellFactory Chocked the resources

2017-02-27 Thread elijah baley
"I am creating a new Thread for every user but If more than one user connect at 
the same time I just allow 1 user to enter the command. "

How do you do that ? Perhaps the load you are experiencing originates from a 
malformed exclusion mechanism

Also, try using the built-in "InteractiveProcessShellFactory.INSTANCE" instead 
of your code


From: Waseem Farooqui 
Sent: Monday, February 27, 2017 9:03 AM
To: dev@mina.apache.org
Subject: Apache MINA SSHd default ShellFactory Chocked the resources

Hi Devs,

I am using Apache MINA server for the ssh server implementation. I
basically want to intercept all the commands typed by the user and the
response sent by the server. I want to execute all the commands on
linux/windows shell. I am using

sshd.setShellFactory(new ProcessShellFactory(new String[]{"/bin/sh", "-i",
"-l"}));
I am creating a new Thread for every user but If more than one user connect
at the same time I just allow 1 user to enter the command. At the same time
all the cpu reached to 100% and all of these resources are taken by /bin/sh.

I am using core i5 cpu 2.50*4 with 8gb RAM and ubuntu 16.04.02 LTS 64bit.

What could be the reason? What should I do to achieve my goal ?

Regards:
Waseem ud din farooqui