Automatically running a command right after logging in over SSH reduces repetitive typing for routine checks, one-off maintenance, and devices that expect a specific entry command instead of a full shell.
When a remote command is configured in PuTTY, the client requests command execution from the SSH server after authentication instead of starting a normal interactive shell. The server runs the command under the authenticated account, returns the output to the terminal window, and ends the session when the command finishes.
Remote commands often run with a different environment than an interactive login, so PATH and shell startup files may not behave as expected. Commands that prompt for input or require a proper terminal (including some sudo workflows) can fail or hang, and fast commands can close the window immediately when they exit.
Steps to run a remote command automatically after connecting in PuTTY:
- Launch PuTTY on Windows.
- Enter the SSH server Host Name (or IP address) and Port in the Session category.
- Open Connection → SSH in the category tree.
- Enter the desired command in the Remote command field.
Prefer absolute paths for non-interactive runs, such as
/usr/bin/top
, to avoid login-dependent PATH differences.
- Enter a name under Saved Sessions to keep the setting for later use.
- Click Save to store the remote command in the session profile.
A saved remote command runs on every connect for that profile, so a destructive command can repeatedly delete data or change configuration unexpectedly.
- Click Open to connect using the configured remote command.
A fast command may close the session immediately after it completes.
- Confirm the command output appears after authentication.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
