Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 2
    To be honest I'd never considered that. I learned that ssh passed its args to the remote shell, and that's where it was executed. As a result I tend to write ssh remoteHost 'some command line…', which reminds me that the some command line… part will be passed verbatim to a remote shell for execution as if I'd typed it directly. (Wrap the line in single quotes to avoid local evaluation, or use double quotes to interpolate local variables.) I'll update my question to include this. Commented Sep 16, 2022 at 9:01
  • 1
    @user253751 ssh doesn't parse the arguments again, it passes them to a shell on the remote system and that parses them. If the remote command wasn't parsed by a remote shell, you couldn't use any shell features like redirects, wildcards, or compound commands (multiple commands separated by ;, ||, &&, or if or while or ...). It looks to me like the real problem here is that you've added a third shell (and a third layer of parsing) by using sh -c. Commented Sep 16, 2022 at 9:29
  • 3
    @user253751 ssh does ask for a remote shell. By definition Commented Sep 16, 2022 at 11:09
  • 1
    @user253751, the remote system might implement some restrictions through the choice of the user's shell, including things like having a restricted or totally customized shell, or even preventing logins by having something like /bin/false as the shell. That's useful and straightforward behaviour and means restrictions like that don't need to be implemented in multiple places (like the SSH server configuration in addition to the user's passwd entry). I wouldn't be surprised if there were compatibility issues with earlier tools like rsh too, but I don't really know about those. Commented Sep 16, 2022 at 14:48
  • 1
    ssh passes the arguments as a single token. concatenation would be: sh-c'echo"0=$01=$2"'arg1arg2arg3 . perhaps i'm splitting hair here, but I would not call what ssh is doing concatenation. Commented Sep 16, 2022 at 17:27