4

I am executing the following in Unix terminal:

client$: ssh host "cat foo.txt"

and expecting the file output and ssh connection to be closed i.e:

bar
client$:

What is actually happening is that no output is produced by cat and the terminal is still on the remote host:

server$ :

I can now do the "cat foo.txt" and get the contents of the file and close the connection with either exit or logout. Ouptut from ssh is:

debug1: Entering interactive session.
debug2: callback start
debug2: client_session2_setup: id 0
debug1: Sending environment.
debug1: Sending env LANG = en_GB
debug2: channel 0: request env confirm 0
debug1: Sending command: cat foo.txt
debug2: channel 0: request exec confirm 0
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel 0: rcvd adjust 2097152

I do have another user account for which this actually works fine but so far I was unable to find a difference in setup/profile that might be causing that behavior. The ssh output for a working user account is:

debug1: Entering interactive session.
debug2: callback start
debug2: client_session2_setup: id 0
debug1: Sending environment.
debug1: Sending env LANG = en_GB
debug2: channel 0: request env confirm 0
debug1: Sending command: cat foo.txt
debug2: channel 0: request exec confirm 0
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel 0: rcvd adjust 2097152
bar
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: channel 0: close_write
debug2: channel 0: output drain -> closed
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug2: channel 0: rcvd close
debug2: channel 0: close_read
debug2: channel 0: input open -> closed
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.2 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 0

Are there any obvious settings that might be causing that? Or any ssh options that can help? I had a look in .bashrc and .bash_profile but I can't see anything that might be the cause. Both users do not have .ssh/config so I think the config is system wide in /etc/ssh/ssh_config. Running ssh -n host "cat foo.txt" closes the connection but still no output from cat:

debug1: Entering interactive session.
debug2: callback start
debug2: client_session2_setup: id 0
debug1: Sending environment.
debug1: Sending env LANG = en_GB
debug2: channel 0: request env confirm 0
debug1: Sending command: cat foo.txt
debug2: channel 0: request exec confirm 0
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel 0: rcvd adjust 2097152
debug2: channel 0: read<=0 rfd 5 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: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: channel 0: close_write
debug2: channel 0: output drain -> closed
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug2: channel 0: rcvd close
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.3 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 0
Kam
  • 43

2 Answers2

3

I'm not sure if this is relevant for your case but I was able to solve a similar problem on an Ubuntu 16.10 by editing .bashrc:

From:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) exit;;
esac

To:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

So if you can find an exit anywhere on your config files, maybe that's what's doing the nasties.

Just replace it with a return.

ᄂ ᄀ
  • 4,187
3

Try using ssh -T "username@"host" "cat foo.txt"

-T stops a pseudo-tty terminal being assigned

or failing that try

echo "cat foo.txt" | ssh "username"@"host"

which should just work like ssh "username"@"host" "cat foo.txt"

just thought of another one instead of the echo, try using

ssh -t -t "username"@"host" "cat foo.txt"

Fegnoid
  • 889