Run simple command line on the remote host using existing SSH configuration


Hi there!

I have the run configuration with some configurable params and SSH config picker based on existing `SSH Configurations` (Settings -> Tools -> SSH Configurations, collected via `SshConfigManager`)

How can I connect to the remote terminal using this SSH config and run some command on it? I think I can use `ColoredRemoteProcessHandler` and `RemoteProcess`, but don't know how exactly.

Comment actions Permalink

Odael, the SSH-related functionality you're asking for is available in IU only and isn't public.

However, you may try using the following method:

com.intellij.ssh.RemoteCredentialsUtil#connectionBuilder(com.intellij.remote.RemoteCredentials, com.intellij.openapi.project.Project, com.intellij.openapi.progress.ProgressIndicator, boolean)
Comment actions Permalink

Thanks! I can build SshSession using this util. but how can I use it to run command on the remote server and how can I wrap it with corresponding ProcessHandler (for example, ColoredRemoteProcessHandler)?

Comment actions Permalink

Use i.e. CapturingSshProcessHandler:

String command = "ls -la";
SshProcess process = RemoteCredentialsUtil.connectionBuilder(credentials).execBuilder(command).execute()
CapturingSshProcessHandler processHandler = new CapturingSshProcessHandler(process, null, command);
ProcessOutput output = processHandler.runProcess();



Please sign in to leave a comment.