İçeriğe geç
Community

KONULARI KEŞFET

Editoryal yaklaşım

CoreTrailKit ile yeni mi tanışıyorsun?

Servislerini izle. Kanıtları elinin altında tut.

CoreTrailKit
Yazılara dön
REHBER/ SSH

SSH command not found: inspect the remote PATH

You can run a tool after logging in manually, but ssh app-server tool ends with command not found. A successful login does not guarantee that the remote command receives the same environment as your interactive shell.

Yazar: CoreTrailKit3 dk okuma

01

Inspect the remote environment, not your laptop’s

Quote the diagnostic command so PATH expands on the remote side. Without the single quotes, the local shell can substitute its own value before SSH runs, leaving you to investigate the wrong environment.

Check the account and the tool with command -v. A version manager, alias, shell function, or tool installed in a user directory may be present only after interactive initialization. An executable also needs a valid interpreter and permissions; not every launch failure is a PATH issue.

sh · ÖRNEK
ssh app-server 'id -un; printf "%s\n" "$PATH"; command -v your-tool'
# Linux account database, if available:
ssh app-server 'getent passwd "$(id -un)"'

02

Compare one missing name with one known path

In the lab we installed a small executable under /home/developer/tools, outside the remote command’s PATH. Invoking lab-tool by name exited 127. Invoking the same file by its absolute path printed our success marker.

No SSH configuration or key changed between those runs. That comparison isolated executable lookup from authentication and transport. It did not require sourcing a large personal shell configuration or granting more privileges.

sh · ÖRNEK
# Replace this with the executable path verified on your server.
ssh app-server '/home/developer/tools/your-tool --version'

03

Make the required environment explicit

If an absolute path is sufficient, use it in the remote command. If a tool needs a particular working directory or environment, define those deliberately in an approved wrapper or command. Keep secrets out of command-line examples and diagnostic output.

For a Linux or macOS remote host with known system directories, the following is a controlled PATH pattern. Adapt it to the real installation; it is not a universal replacement for every distribution, version manager, or service environment.

sh · ÖRNEK
ssh app-server 'PATH=/opt/my-tool/bin:/usr/bin:/bin; export PATH; cd /srv/my-app && /opt/my-tool/bin/your-tool --version'

04

Avoid treating a TTY as an environment repair

Requesting a pseudo-terminal changes terminal behavior but does not make every remote command a login shell. Similarly, invoking a login shell deliberately can run profile scripts with side effects and still differ from the session you expected.

Bash documents distinct startup paths for interactive, login, and remote shell invocations. Read the rules for the shell actually configured on the server. Move automation requirements into an explicit interface instead of adding more output and initialization to every login.

05

Check the remote result and exit status

A command that prints something can still fail later. Capture SSH’s exit status immediately; for an ordinary remote command, SSH returns the remote command status, while its own connection errors use 255. Avoid adding a successful trailing command that masks the operation you care about.

Our test separately confirmed a missing-name exit of 127, a successful absolute-path execution, and propagation of an explicit remote exit 7. These checks distinguish a working transport from a successful remote operation.

sh · ÖRNEK
ssh app-server '/home/developer/tools/your-tool --version'
remote_status=$?
printf 'SSH/remote exit status: %s\n' "$remote_status"

Sınırları bil

The controlled test uses a Linux Bash account and a small executable installed outside its non-interactive PATH. Bash startup rules differ from other shells, and Bash has special behavior for some remote invocations. We do not assume that all SSH commands skip every startup file.

Kaynaklar ve ileri okuma

CoreTrailKit tarafından hazırlanan teknik yayın.

Bütün yazıları keşfet

KEŞFETMEYE DEVAM ET