SSH2 and PHP not working 'Terminal'

1.7k Views Asked by At

Whenever I try and execute

if (!($stream = ssh2_exec($con, "cd $dir; screen -S creative java -Xmx500M -Xms500M -jar spigot.jar" ))) {

it keeps returning with 'Must be connected to a terminal.' which I can't seem to get around. How do I get around/fix this?

3

There are 3 best solutions below

0
On BEST ANSWER

Test this : You should pass a pty emulation name ("vt102", "ansi", etc...) if you want to emulate a pty, or NULL if you don't.

Passing false will convert false to a string, and will allocate a "" terminal.

cf. http://php.net/manual/fr/function.ssh2-exec.php

0
On

You could try to use phpseclib's read() / write() functions. eg.

<?php
include('Net/SSH2.php');

$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
    exit('Login Failed');
}

echo $ssh->read('username@username:~$');
$ssh->write("ls -la\n"); // note the "\n"
echo $ssh->read('username@username:~$');
0
On

Starting screen like you did requires a valid TTY because of it get's attached to your session. The ssh implementation of PHP just doesn't create a session like that.

Starting screen detached should do the trick:

screen -d -m [<command>]

So your code would look like:

if (!($stream = ssh2_exec($con, "cd $dir; screen -d -m -S creative java -Xmx500M -Xms500M -jar spigot.jar" ))) {