I've seen the questions and answers about needing to double-escape the arguments to remote ssh commands. My question is: Exactly where and when does the second parsing get done?
If I run the following:
$ ssh otherhost pstree -a -p
I see the following in the output:
|-sshd,3736
| `-sshd,1102
| `-sshd,1109
| `-pstree,1112 -a -p
The parent process for the remote command (pstree
) is sshd
, there doesn't appear to be any shell there that would be parsing the command line arguments to the remote command, so it doesn't seem as if double quoting or escaping would be necessary (but it definitely is). If instead I ssh there first and get a login shell, and then run pstree -a -p
I see the following in the output:
├─sshd,3736
│ └─sshd,3733
│ └─sshd,3735
│ └─bash,3737
│ └─pstree,4130 -a -p
So clearly there's a bash
shell there that would do command line parsing in that case. But the case where I use a remote command directly, there doesn't seem to be a shell, so why is double quoting necessary?
man ssh
seems to contradict this. It says, "If a command is specified, it is executed on the remote host instead of a login shell." – Maxpm Dec 17 '20 at 19:33-
, which tells shells to do their login-shell behavior such as reading.profile
. In my answer, where I've added a clarification, I mean the shell that's registered as the user's shell in the user database (/etc/passwd
or equivalent). – Gilles 'SO- stop being evil' Dec 19 '20 at 19:56