Reputation: 80
I am trying to add an additional script to my PHP deployer script to open an SSH session on my hosting server.
Amongst the welcome message from the remote server, there is an error message:
the input device is not a TTY
Then I get an "exit code 1 (General error)" at the end, and it exits back to my local docker terminal.
Here is my script so far:
task('remotessh', function () {
$host = currentHost();
$hostname = $host->getHostname();
$remoteUser = $host->get('remote_user');
if (!$remoteUser) {
throw new \RuntimeException("Remote user not set for host.");
}
$sshCommand = "ssh -T $remoteUser@$hostname";
runLocally($sshCommand, ['tty' => true]);
});
Note: when I manually run ssh {remoteUser}@{hostname}
in the same docker terminal, I can start an ssh session just fine.
Note 2: when I add -v flag there is some relevant output:
[server.com] err debug1: Offering public key: /home/user/.ssh/id_rsa RSA SHA256:xxx
[server.com] err debug1: Server accepts key: /home/user/.ssh/id_rsa RSA SHA256:xxx
[server.com] err debug1: Authentication succeeded (publickey).
[server.com] err Authenticated to server.com ([IP Address]:22).
[server.com] err debug1: channel 0: new [client-session]
[server.com] err debug1: Requesting [email protected]
[server.com] err debug1: Entering interactive session.
[server.com] err debug1: pledge: network
[server.com] err debug1: client_input_global_request: rtype [email protected] want_reply 0
[server.com] err debug1: Remote: /data/docker0/ssh/user/login/.ssh/authorized_keys:6: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
[server.com] err debug1: Remote: /data/docker0/ssh/user/login/.ssh/authorized_keys:6: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
[server.com] err debug1: Sending environment.
[server.com] err the input device is not a TTY
Any ideas how I can get this running?
Upvotes: 1
Views: 210
Reputation: 4158
To forcibly allocate a TTY you have to specify -t
. From the ssh manual page
Force pseudo-terminal allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple
-t
options force tty allocation, even if ssh has no local tty.
So in my opinion you have to use
$sshCommand = "ssh -t $remoteUser@$hostname";
runLocally($sshCommand, ['tty' => true]);
Maybe you have to specify ssh -ttt $remoteUser@$hostname
.
Upvotes: 0