Repeated SSH connections for account checks or status reports often begin with the same command. PuTTY can store that remote command in a saved session so it runs automatically after login.
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:
- Enter your SSH server's hostname in Host Name (or IP address) under Session.
An SSH server and an account that already authenticate successfully with PuTTY are required. The example uses
server.example.comon port22. If your server uses another SSH port, enter it in Port. - Open Connection → SSH in the category tree.

- Enter your command in Remote command.
The
idcommand prints the remote account's user ID and groups on a Unix-like server:/bin/sh -c 'id'
A saved remote command runs on every connection using that profile, so a destructive command can repeatedly delete data or change configuration unexpectedly.
- Return to Session in the category tree.

- Select Never under Close window on exit.
This keeps a fast command's output visible after the remote session ends.
- Enter a name such as
my-serverunder Saved Sessions.
- Click Save to store the command in that session.

- Click Open to connect with the saved command.
Normal SSH authentication still applies; the command starts only after authentication succeeds.
- Dismiss the Connection closed by remote host notice with OK if it appears.

- Confirm the command output appears without typing a command in the terminal.
uid=911(abc) gid=911(abc) groups=911(abc),1000(users)
The example output identifies the remote
abcaccount; your account's IDs and groups will differ. PuTTY (inactive) indicates that the session has ended, while Never retains its output.