sshj icon indicating copy to clipboard operation
sshj copied to clipboard

session.setEnvVar throws ConnectionError

Open selimober opened this issue 11 years ago • 7 comments

I'm testing to connect to localhost. I manage to connect and execute a command without session.setEnvVar.

With session.setEnvVar enabled it throws:

net.schmizz.sshj.connection.ConnectionException: Request failed
at net.schmizz.sshj.connection.channel.AbstractChannel.gotResponse(AbstractChannel.java:401)
at net.schmizz.sshj.connection.channel.AbstractChannel.handle(AbstractChannel.java:204)
at net.schmizz.sshj.connection.ConnectionImpl.handle(ConnectionImpl.java:128)
at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:475)
at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:127)
at net.schmizz.sshj.transport.Decoder.received(Decoder.java:195)
at net.schmizz.sshj.transport.Reader.run(Reader.java:72)

The code is as follows:

    SSHClient ssh = new SSHClient();
    ssh.addHostKeyVerifier(new PromiscuousVerifier());
    ssh.connect("192.168.1.99"); //localhost
    TaskRunResponse response;
    try {
        ssh.authPassword("user", "pwd");
        Session session = ssh.startSession();
        try {
            session.setEnvVar("testenv", "123");
            Session.Command cmd = session.exec("/Users/selimober/tmp/paramandenvtest.sh 10");
            cmd.join();
            String output = IOUtils.readFully(cmd.getInputStream()).toString();
            Integer exitStatus = cmd.getExitStatus();
            response = new TaskRunResponse(ExitStatus.SUCCESS, output);
        } finally {
            session.close();
        }
    } finally {
        ssh.disconnect();
    }

Version: net.schmizz:sshj:0.9.0 Server: SSH-2.0-OpenSSH_6.2

selimober avatar Feb 17 '14 16:02 selimober

I'm running into this issue as well. Currently in the thick of a deadline, but I'll try to help debug/fix this when I get some downtime here.

mdwn avatar Apr 23 '15 15:04 mdwn

I too am running into this issue. Any idea of a temporary work-around?

I'm connecting to a CentOS 6.6 running OpenSSH 5.3p1 if this helps.

Jepod avatar Nov 05 '15 19:11 Jepod

Which version of sshj?

Op do 5 nov. 2015 20:56 schreef James Poulsen [email protected]:

I too am running into this issue. Any idea of a temporary work-around?

— Reply to this email directly or view it on GitHub https://github.com/hierynomus/sshj/issues/128#issuecomment-154172740.

hierynomus avatar Nov 05 '15 21:11 hierynomus

I meant to say that too, sorry. It's version SSHJ 0.14.0.

However, I'm starting to think it's not a bug in SSHJ as I can't use Putty to set environmental variables on initial connection either. I'm going to look into this further.

Jepod avatar Nov 05 '15 21:11 Jepod

Anyone found the solution for this?

adraghici avatar Apr 27 '16 18:04 adraghici

As far as I know the server should allow setting environment variables. For OpenSSH it should be set in /etc/sshd_config.

Tuchkata avatar Aug 11 '16 16:08 Tuchkata

@hierynomus I am facing this issue in CentOs 7 with SSHJ version 0.31.0. Any alternative solution for this issue to set envVars while executing the command?

Which version of sshj?

Op do 5 nov. 2015 20:56 schreef James Poulsen [email protected]:

I too am running into this issue. Any idea of a temporary work-around? — Reply to this email directly or view it on GitHub #128 (comment).

adarshhm6 avatar Dec 28 '22 08:12 adarshhm6