4

In my SSH config file, I have to enable the RequestTTY force for some important reasons. And currently my config file looks like this:

Host x.x.x.x
    HostName yyyy
    StrictHostKeyChecking no
    RequestTTY force
    IdentityFile ~/path/id_rsa

But now when I execute an scp command, it completes but creates an empty file on the destination path and below is the log that it generates:

debug2: channel 0: read<=0 rfd 4 len 0
debug2: channel 0: read failed
debug2: channel 0: close_read
debug2: channel 0: input open -> drain
debug2: channel 0: ibuf empty
debug2: channel 0: send eof
debug2: channel 0: input drain -> closed
debug2: channel 0: write failed
debug2: channel 0: close_write
debug2: channel 0: send eow
debug2: channel 0: output open -> closed

But if I comment out the RequestTTY force option in the config file, it executes properly and also copies the file properly.

Why does this behaviour occur? Can anyone provide me with a workaround so that I won't have to disable the RequestTTY force option and also the file would be copied properly?

3
  • 1
    Define "some important reasons".
    – Jakuje
    Apr 22 '16 at 10:02
  • In my code I execute sudo commands over SSH. Normally they work fine but when it comes to RHEL machines, it throws an error regarding TTY allocation. So I have to force the allocation for my codes to run on RHEL machines too.
    – Punit Naik
    Apr 22 '16 at 10:08
  • Instead of using force you can just use yes, and it normally detected tty pretty well, and scp will work too
    – texasbruce
    Feb 3 at 20:34
8

There are many possible solutions for that:

  • You can configure sudo not to require tty: RequireTTY in /etc/sudoers
  • You can force tty allocation on command-line in these specific cases, where you need it: ssh -tt host command
  • You can tell scp not to allocate TTY by -T or -o RequestTTY=no command-line option: scp -T file host:path/ or scp -o RequestTTY=no file host:path/

The reasons why does it happen are already explained. You spoil binary protocol by TTY control characters and vice versa.

6
  1. SCP protocol is binary one.
  2. With TTY enabled, the control characters have their meaning.

So as soon as the TTY sees a character in the SCP protocol binary data that appears as a control character, it interprets it. Particularly as soon as there's ^C (ASCII 0x03), it aborts the SCP process.

Use ssh -t to force TTY for interactive sessions, instead of forcing it globally using RequestTTY.

8
  • So what would be a possible solution for this?
    – Punit Naik
    Apr 22 '16 at 7:43
  • Why do you need the RequestTTY? Apr 22 '16 at 7:49
  • In my code I execute sudo commands over SSH. Normally they work fine but when it comes to RHEL machines, it throws an error regarding TTY allocation. So I have to force the allocation for my codes to run on RHEL machines too.
    – Punit Naik
    Apr 22 '16 at 7:52
  • 1
    Cannot you use ssh -t instead of global configuration? Apr 22 '16 at 8:17
  • 1
    Why not run scp with that option set to no? You can even alias it alias scp='scp -oRequestTTY=no' Edit:Jakuje has a better option below: scp -T.
    – prateek61
    Apr 22 '16 at 10:55
0

For me, the following worked:

Host *.bla.fasel.com
   User horst
   RequestTTY yes

ssh with sudo -i:

$ ssh guenther.bla.fasel.com sudo -i
horst@guenther.bla.fasel.com's password:
root@guenther.bla.fasel.com:~#

scp with username/password auth:

$ scp guenther.bla.fasel.com:/etc/passwd .
Pseudo-terminal will not be allocated because stdin is not a    terminal.
horst@guenther.bla.fasel.com's password:
passwd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.