Folks-
It seems that the existing software does not allow you to create an SSH2 connection with a tty
setup on the target machine, but does work fine with an SSH1 connection. This bug was
identified (an pretty much fixed) a long time ago:
http://www.derkeiler.com/Newsgroups/comp.security.ssh/2003-05/0097.html
This problem is also described at:
http://www.perlmonks.org/?node_id=732192
The attached file is example code that will expose the problem.
The fix is pretty much what Quackie tried back in 2003. Here is my version of his code, that
seems to make it work on my machine:
sub cmd {
my $ssh = shift;
my($cmd, $stdin) = @_;
my $cmgr = $ssh->channel_mgr;
my $channel = $ssh->_session_channel;
$channel->open;
$channel->register_handler(SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, sub {
my($channel, $packet) = @_;
$channel->{ssh}->debug("Sending remote TTY request...");
# CMV MODS *********
my $r_packet = $channel->request_start('pty-req', 0);
my($term) = $ENV{TERM} =~ /(\w+)/;
$r_packet->put_str($term);
$r_packet->put_int32(0) for 1..4; # For terminal size (I think)...
$r_packet->put_str("");
$r_packet->send;
$channel->{ssh}->debug("Sending command: $cmd");
$r_packet = $channel->request_start("exec", 0);
$r_packet->put_str($cmd);
$r_packet->send;
# CMV MODS *********
This is from SSH2.pm V1.38. I would suggest that final implementation check for the use_pty
setting and only execute it if requested by the user. Also retrieving and setting the current
terminal size (as implemented in SSH2.pm version 1.46 in the shell() subroutine) would
probably be a good idea as well.
-Craig