<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pawar Manoj on Medium]]></title>
        <description><![CDATA[Stories by Pawar Manoj on Medium]]></description>
        <link>https://medium.com/@mmpawar94?source=rss-e9618b75fd94------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*W6PzD-n91NfHFqpa</url>
            <title>Stories by Pawar Manoj on Medium</title>
            <link>https://medium.com/@mmpawar94?source=rss-e9618b75fd94------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 15:19:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mmpawar94/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to execute Linux/Unix command on remote server using SSH]]></title>
            <link>https://mmpawar94.medium.com/how-to-execute-linux-unix-command-on-remote-server-using-ssh-ab2e2c8bd2d1?source=rss-e9618b75fd94------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab2e2c8bd2d1</guid>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[sftp]]></category>
            <category><![CDATA[remote]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Pawar Manoj]]></dc:creator>
            <pubDate>Sat, 03 Apr 2021 05:03:23 GMT</pubDate>
            <atom:updated>2021-04-04T02:19:24.877Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>How to execute Linux/Unix command on a remote server using Java SSH</strong></h3><p>The JSsh-client is a Java-based library build on top of the Jsch Library to perform an operation on the remote server over SSH and SFTP channel. It has the following features,</p><ul><li>Test SSH connection with a remote SSH server</li><li>Execute a command on a remote server using Execute Channel</li><li>Execute commands on a remote server using Shell channel</li><li>Upload/Download the file to/from the remote server from/to local using the SFTP channel</li></ul><h3>How to use it?</h3><h3>Step 1: Add Maven Dependency to POM.xml [use lastest version]</h3><p>Current version: 1.0</p><pre>&lt;properties&gt;<br>   &lt;jssh-client.verion&gt;1.0&lt;/jssh-client.verion&gt;<br>   &lt;jcraft.version&gt;0.1.55&lt;/jcraft.version&gt;<br>   &lt;common-lang3.version&gt;3.12.0&lt;/common-lang3.version&gt;<br>   &lt;commons-io.version&gt;2.8.0&lt;/commons-io.version&gt;<br>&lt;/properties&gt;</pre><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;io.github.manojpawar94&lt;/groupId&gt;<br>    &lt;artifactId&gt;jssh-client&lt;/artifactId&gt;<br>    &lt;version&gt;${jssh-client.verion}&lt;/version&gt;<br>&lt;/dependency&gt;</pre><pre>&lt;!-- https://mvnrepository.com/artifact/com.jcraft/jsch --&gt;&lt;dependency&gt;<br>   &lt;groupId&gt;com.jcraft&lt;/groupId&gt;<br>   &lt;artifactId&gt;jsch&lt;/artifactId&gt;<br>   &lt;version&gt;${jcraft.version}&lt;/version&gt;<br>&lt;/dependency&gt;</pre><pre>&lt;!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 --&gt;<br>&lt;dependency&gt;<br>    &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;<br>    &lt;artifactId&gt;commons-lang3&lt;/artifactId&gt;<br>    &lt;version&gt;${common-lang3.version}&lt;/version&gt;<br>&lt;/dependency&gt;</pre><pre>&lt;!-- https://mvnrepository.com/artifact/commons-io/commons-io --&gt;&lt;dependency&gt;<br>   &lt;groupId&gt;commons-io&lt;/groupId&gt;<br>   &lt;artifactId&gt;commons-io&lt;/artifactId&gt;<br>   &lt;version&gt;${commons-io.version}&lt;/version&gt;<br>&lt;/dependency&gt;</pre><p>Git Repository Link: <a href="https://github.com/manojpawar94/jssh-client">https://github.com/manojpawar94/jssh-client</a></p><h3>Step 2: Get Instance of JsshClient</h3><p>JsshClient is an interface. It has a singleton implementation class JscraftClient. We can get an instance of the class as below</p><pre>JSshClient client = JcraftClient.getInstance();</pre><h3>Step 3: Create the JsshProxy Object instance</h3><p>It has various options to set based upon our needs. It supports both password-based and SSH key-based authentication mechanism. To set authentication mechanism we need to set respective attributes to the JSshProxy object.</p><pre>java.util.Properties properties = new java.util.Properties();<br>JSshProxy&lt;?&gt; jSshProxy = JSshProxy.builder()<br>                    .hostname(&quot;123.12.34.5&quot;)<br>                    .port(22)<br>                    .username(&quot;test&quot;)<br>                    .password(&quot;test@123&quot;)<br>                    //.privateKey(&quot;&quot;)<br>                    .knownHostsFileName(&quot;&quot;)<br>                    .sessionTimeOut(10000)<br>                    .channelTimeOut(5000)<br>                    .properties(properties)<br>                    .enablePty(true)<br>                    //.ptyType(&quot;ANSI&quot;) used only for shell channel operation<br>                    .build();</pre><h3>Step 4a: Test SSH connection with Remote Server</h3><pre>JSshProxy&lt;?&gt; jSshProxy = JSshProxy.builder()<br>                    .hostname(&quot;123.12.34.5&quot;)<br>                    .username(&quot;test&quot;)<br>                    .password(&quot;test@123&quot;)<br>                    .enablePty(true)<br>                    .build();</pre><pre>JSshResult jSshResult = client.testSSH(jSshProxy);</pre><h3>Step 4b: Execute a command on a remote server using Execute Channel</h3><pre>String command = &quot;ls -lrt&quot;;<br>JSshProxy&lt;String&gt; jSshProxy = JSshProxy.builder()<br>                                        .hostname(&quot;123.12.34.5&quot;)<br>                                        .username(&quot;test&quot;)<br>                                        .password(&quot;test@123&quot;)<br>                                        .enablePty(true)<br>                    .task(command)<br>                                        .build();<br>JSshResult jSshResult = client.execute(jSshProxy);</pre><h3>Step 4c: Execute a command on a remote server using Execute Channel</h3><pre>ShellCommand command = ShellCommand.builder()<br>                .command(&quot;ls -lrt&quot;)<br>                .command(&quot;pwd&quot;)<br>                .command(&quot;who i am&quot;)<br>                .build();</pre><pre>JSshProxy&lt;ShellCommand&gt; jSshProxy = JSshProxy.builder()<br>                                        .hostname(&quot;123.12.34.5&quot;)<br>                                        .username(&quot;test&quot;)<br>                                        .password(&quot;test@123&quot;)<br>                                        .enablePty(true)<br>                                        .task(command)<br>                                        .build();<br>JSshResult jSshResult = client.shell(jSshProxy);</pre><h3>Step 4d: Upload the file to the remote server from local using the SFTP channel</h3><pre>String from = &quot;C:\\Users\\sample_file_to_upload.txt&quot;;<br>String to = &quot;/home/user/upload&quot;;</pre><pre>SftpCommand command = SftpCommand.builder()<br>                    .from(from)<br>                    .to(to)<br>                    .sftpType(SftpType.PUT)<br>                    .build();</pre><pre>JSshProxy&lt;ShellCommand&gt; jSshProxy = JSshProxy.builder()<br>                                        .hostname(&quot;123.12.34.5&quot;)<br>                                        .username(&quot;test&quot;)<br>                                        .password(&quot;test@123&quot;)<br>                                        .enablePty(true)<br>                                        .task(command)<br>                                        .build();<br>JSshResult jSshResult = client.sftp(jSshProxy);</pre><h3>Step 4e: Download the file from the remote server to local using the SFTP channel</h3><pre>String from = &quot;/home/user/sample_file_to_download.txt&quot;;<br>String to = &quot;C:\\Users\\Downloads&quot;;</pre><pre>SftpCommand command = SftpCommand.builder()<br>                                        .from(from)<br>                                        .to(to)<br>                                        .sftpType(SftpType.GET)<br>                                        .build();</pre><pre>JSshProxy&lt;ShellCommand&gt; jSshProxy = JSshProxy.builder()<br>                                        .hostname(&quot;123.12.34.5&quot;)<br>                                        .username(&quot;test&quot;)<br>                                        .password(&quot;test@123&quot;)<br>                                        .enablePty(true)<br>                                        .task(command)<br>                                        .build();<br>JSshResult jSshResult = client.sftp(jSshProxy);</pre><p>Git Repository Link: <a href="https://github.com/manojpawar94/jssh-client">https://github.com/manojpawar94/jssh-client</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab2e2c8bd2d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>