ssh -t remotehost vim /tmp/x.txt
I know that I can run a command like the above.
But I would like to be able to run any local bash code in a remote machine. For this reason, I'd like to call the remote 'bash -s' so that can process any local bash code.
ssh -t remotehost 'bash -s' <<< vim /tmp/x.txt
However, the above example shows "Pseudo-terminal will not be allocated because stdin is not a terminal." Is there any way to let ssh take local bash code via stdin and run it via the remote 'bash -s'? Thanks.
Best Answer
You're getting the "Pseudo-terminal will not be allocated..." message because you're running ssh with a single
-t
option, when the standard input to the ssh process isn't a TTY. ssh prints that message specifically in this case. The documentation for -t says:The
-t
command-line option is related to the ssh configuration option RequestTTY:A single
-t
is equivalent to "RequestTTY yes", while two of them is equivalent to "RequestTTY force".If you want your remote command(s) to run with a TTY, then specify
-t
twice:ssh will allocate a TTY for the remote system and it won't print that message.
If the command(s) being run on the remote system don't require a TTY, you can leave the
-t
option out: