ssh-argv0
Execute ssh command, preserving argv[0]
SYNOPSIS
This is not a direct command with a standard synopsis. Instead, it describes a method of invoking OpenSSH binaries via symbolic or hard links:
ln -s /path/to/ssh /path/to/new_name
new_name [options] [arguments]
For example, to make the ssh binary behave like scp:
ln -s /usr/bin/ssh /usr/local/bin/scp
scp [options] [source] [destination]
This technique enables a single ssh executable to emulate other OpenSSH commands like scp or sftp based on the name it is executed under.
PARAMETERS
N/A
This command has no direct parameters, as it is a concept describing how other commands are invoked. The parameters applicable depend on the specific OpenSSH command (e.g., ssh, scp, sftp) that the binary behaves as, determined by its invocation name (argv[0]). Refer to the man pages of the respective commands for their specific options.
DESCRIPTION
ssh-argv0 is not a standalone command but rather a convention or technique used in Unix-like systems, particularly with OpenSSH. It refers to how the ssh binary can adjust its behavior based on the name it's invoked with (the value of argv[0], the first argument passed to a program).
This allows a single binary to act as different commands, such as scp or sftp, when symlinked or hardlinked to those respective names. This technique is valuable for saving disk space and simplifying deployments, especially in minimal or embedded environments where resources are constrained.
For instance, if /usr/bin/ssh is symbolically linked to /usr/local/bin/scp, executing scp will actually run the ssh binary. The ssh binary then inspects its own invocation name (argv[0]) and, recognizing 'scp', changes its internal execution path to behave as the scp command.
CAVEATS
- Not a direct, executable command; it describes a behavior or convention.
- Relies on the creation and management of symbolic or hard links.
- The exact behavior and support for this technique can depend on the specific OpenSSH implementation and how it was compiled. Some systems might use separate binaries for scp or sftp for various reasons, or provide them as shell script wrappers.
- While common for scp and sftp, this `argv[0]` method is not typically used for other OpenSSH tools like ssh-keygen or ssh-agent, which are usually distinct binaries.
HOW IT WORKS
When a program is executed, the operating system passes the name by which it was invoked as the first argument in the `argv` array (specifically `argv[0]`) to the program's `main` function. Programs like the OpenSSH ssh binary are specifically designed to inspect this `argv[0]` value. If `argv[0]` matches 'scp', the binary executes the scp logic; if it matches 'sftp', it executes the sftp logic, and so on. This intelligent self-configuration enables a single executable file to serve multiple command functionalities efficiently.
SECURITY IMPLICATIONS
While convenient for resource management, this method introduces a subtle point for security. If an attacker could control `argv[0]` (e.g., by creating malicious symlinks in a user's PATH or manipulating execution paths), they might potentially trick a program into behaving differently than intended. However, in the context of OpenSSH, the use of `ssh-argv0` is typically confined to trusted system paths and relies on system administrators creating the necessary links, mitigating most common security risks related to `argv[0]` manipulation.
HISTORY
The concept of a program's behavior being determined by argv[0] is fundamental to Unix and dates back to its early days. It has been used by core utilities like sh (which can become bash, dash, etc., based on invocation) and is a cornerstone of projects like BusyBox, which consolidate many common utilities into a single executable for embedded systems.
For OpenSSH, this technique gained prominence to facilitate compact installations. By allowing scp and sftp to be implemented as symbolic links to the main ssh executable, disk space is conserved, and dependency management is simplified. This approach proved particularly beneficial in resource-constrained environments or for streamlining the deployment of OpenSSH suites.