This is kind of related to What defines the maximum size for a command single argument?. But it is about the shell itself.
I want to know what defines the maximum size or string length of an command used via ssh
. Example would be $ ssh user@remote "echo very big command"
.
I found some scripts simply testing it via trail and error. But I assume there is a better way. But first I would like to understand what defines that maximum length of the string.
Here is an example on how I trigger errors about the max length:
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from subprocess import Popen
>>> Popen(['ssh', 'user@localhost', 'echo', '{}'.format('T' * 500000)])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 7] Argument list too long: 'ssh'
The limit on my system (Debian 11 on ARM64hf) starts round about 131067
characters (excluding the starting ssh
, echo
, etc). But getconf ARG_MAX
is much higher 2097152
.
ssh
command. It, too, must be executed by anexec()
function and adhere to the same restrictions as any other command. The answers to the question that you link to seems to answer your question here. – Kusalananda Nov 14 '22 at 11:59echo
local withoutssh
. But then what isARG_MAX
about which is much higher? – buhtz Nov 14 '22 at 12:02getconf ARG_MAX
" and this blog post was the 3rd listing: https://mina86.com/2021/the-real-arg-max-part-1/ I don't know how correct it is, but it seems to answer your question about the difference between the size of the shell's limit on an individual command-line argument and the size of exec() that's governed by ARG_MAX. – Sotto Voce Nov 14 '22 at 16:29