Confused between âecho command | ssh serverâ and âssh server commandâ

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
6
down vote
favorite
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.
scripting login
add a comment |Â
up vote
6
down vote
favorite
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.
scripting login
As a side note,ssh -t server cmdis a better equivalent toecho cmd|ssh serveras 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.
â Duncan X Simpson
Jul 30 at 17:23
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
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.
scripting login
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.
scripting login
edited Jul 30 at 10:31
JayTheKay
1032
1032
asked Jul 30 at 5:32
Karthik
333
333
As a side note,ssh -t server cmdis a better equivalent toecho cmd|ssh serveras 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.
â Duncan X Simpson
Jul 30 at 17:23
add a comment |Â
As a side note,ssh -t server cmdis a better equivalent toecho cmd|ssh serveras 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.
â Duncan X Simpson
Jul 30 at 17:23
As a side note,
ssh -t server cmd is a better equivalent to echo 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.â Duncan X Simpson
Jul 30 at 17:23
As a side note,
ssh -t server cmd is a better equivalent to echo 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.â Duncan X Simpson
Jul 30 at 17:23
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
10
down vote
accepted
man ssh documents that:
If a command is specified, it is executed on the remote host instead of a login shell.
The reason is then that in one case you specified a command, and in the other you didn't, and ssh deliberately (by design) behaves differently in those cases.
In the one where you didn't provide a command, a login shell was launched and it read the piped input and executed it. In the one where you did provide a command, it was launched instead.
Prompting for the password is unrelated. That is authenticating you to the server, before the shell or command is launched.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
10
down vote
accepted
man ssh documents that:
If a command is specified, it is executed on the remote host instead of a login shell.
The reason is then that in one case you specified a command, and in the other you didn't, and ssh deliberately (by design) behaves differently in those cases.
In the one where you didn't provide a command, a login shell was launched and it read the piped input and executed it. In the one where you did provide a command, it was launched instead.
Prompting for the password is unrelated. That is authenticating you to the server, before the shell or command is launched.
add a comment |Â
up vote
10
down vote
accepted
man ssh documents that:
If a command is specified, it is executed on the remote host instead of a login shell.
The reason is then that in one case you specified a command, and in the other you didn't, and ssh deliberately (by design) behaves differently in those cases.
In the one where you didn't provide a command, a login shell was launched and it read the piped input and executed it. In the one where you did provide a command, it was launched instead.
Prompting for the password is unrelated. That is authenticating you to the server, before the shell or command is launched.
add a comment |Â
up vote
10
down vote
accepted
up vote
10
down vote
accepted
man ssh documents that:
If a command is specified, it is executed on the remote host instead of a login shell.
The reason is then that in one case you specified a command, and in the other you didn't, and ssh deliberately (by design) behaves differently in those cases.
In the one where you didn't provide a command, a login shell was launched and it read the piped input and executed it. In the one where you did provide a command, it was launched instead.
Prompting for the password is unrelated. That is authenticating you to the server, before the shell or command is launched.
man ssh documents that:
If a command is specified, it is executed on the remote host instead of a login shell.
The reason is then that in one case you specified a command, and in the other you didn't, and ssh deliberately (by design) behaves differently in those cases.
In the one where you didn't provide a command, a login shell was launched and it read the piped input and executed it. In the one where you did provide a command, it was launched instead.
Prompting for the password is unrelated. That is authenticating you to the server, before the shell or command is launched.
answered Jul 30 at 5:37
Michael Homer
42.1k6107146
42.1k6107146
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f459252%2fconfused-between-echo-command-ssh-server-and-ssh-server-command%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
As a side note,
ssh -t server cmdis a better equivalent toecho cmd|ssh serveras 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.â Duncan X Simpson
Jul 30 at 17:23