Reputation: 33
In a bash script, I use a ssh command as such
ssh mylogin@myremotemachine '*some command/command list separated with ;*'
The local and remote machines have keyless ssh. The command runs fine and gives desired output. But my question is will the ssh session end by itself after executing the command or do we need to close it explicitly given some other commands to it?
If it was not a bash script, we would have given
ssh mylogin@myremotemachine
That remote session would open and be visible. Execute the commands we want. Then exit
to come out of remote session and continue on local session. Does bash script also need this explicit exit?
Upvotes: 0
Views: 518
Reputation: 295403
When the user's identity has been accepted by the server, the server either executes the given command in a non-interactive session or, if no command has been specified, logs into the machine and gives the user a normal shell as an interactive session.
So, only if "no command has been specified" is an interactive session created.
ssh somehost "somecommands here"
, on somehost, runs "$SHELL" -c 'somecommands here'
when not otherwise configured ($SHELL
being subject to the user's account configuration).
When a POSIX-compatible shell is started this way, it runs in noninteractive mode, and exits immediately when the given commands are complete.
Upvotes: 1