0

I'm trying to write a program that connects via SSH to a remote Linux server using Java.

I've found a number of examples online to do this using the JSch package, but they're mostly for issuing a single command to the server right after authentication.

Is there any way, however, to first authenticate with the SSH server, then, over the connection, issue commands from the user input like you would via a remote shell?

1

1 Answer 1

1

If you want to implement an interactive shell, you need to use SSH "shell" channel.

JSch has a simple example showing how to do that:
http://www.jcraft.com/jsch/examples/Shell.java.html (link to archive)

Though note that fully implementing an interactive shell is an immense work. So you will likely find out that a simple implementation like above will not work as you might hope.

For some background, see also:
What is the difference between the 'shell' channel and the 'exec' channel in JSch

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.