Yogesh Rathi Yogesh Rathi - 1 year ago 170
Android Question

How to start ssh sever android programmatically, and how i will get username and password for connect to device

I am developing app like sshdroid.

i want to open ssh connection on android os, and i want to connect app from pc.

I used JSCH lib , but this lib is used to connect android to pc.
and my requirement is pc to android,
any one know any lib or any source code is available.

I already tried.

connectbot.(it is unmaintained lib).
JSCH lib (it is connect android to pc).
SSHelper_source (not help to me).
SSHJ ( tried not helpful).

Answer Source
public void startSSHServer() {
    int port = 8888;
    SshServer sshd = SshServer.setUpDefaultServer();
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(
            .<NamedFactory<Command>> asList(new SftpSubsystem.Factory()));
    sshd.setCommandFactory(new ScpCommandFactory());
    sshd.setShellFactory(new ProcessShellFactory(new String[] { "/system/bin/sh", "-i", "-l" })); // necessary if you want to type commands over ssh
    sshd.setPasswordAuthenticator(new PasswordAuthenticator() {

        public boolean authenticate(String u, String p, ServerSession s) {
            return ("sftptest".equals(u) && "sftptest".equals(p));

    try {
    } catch (IOException e) {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download