During the course of my learning about the non-interactive login shell, I have come across 2 ways to remotely execute the commands via SSH. For me, they both look to be the same. But unfortunately, they aren't.
With the command echo "shopt login_shell; echo \$-" | ssh -l poweruser 192.168.1.67
, I get the following output.
Pseudo-terminal will not be allocated because stdin is not a terminal.
poweruser@192.168.1.67's password:
login_shell on
hBs
But with the command ssh -l poweruser 192.168.1.67 "shopt login_shell; echo \$-"
, I get a different output.
poweruser@192.168.1.67's password:
login_shell off
hBc
Could you please tell why the shell is not a login shell in the second case even though it prompts for the password.
ssh -t server cmd
is a better equivalent toecho cmd|ssh server
as without -t, the default for no explicit command (ssh server
) is to open a pseudo-terminal whereas the default for with a command (ssh server cmd
) is NOT to open one. The -t forces it to open one anyway. – Dessa Simpson Jul 30 '18 at 17:23