Automatically logging SSH and serial sessions in PuTTY is essential for auditing, troubleshooting, and compliance. Instead of manually specifying a static filename or overwriting previous session captures, PuTTY supports built-in wildcard variables to dynamically generate unique, structured log paths based on target hosts, timestamps, and connection ports.
Configuring Dynamic Log File Names
In PuTTY, navigate to Session > Logging in the left sidebar. Under Session logging, select "All session output" (or "Printable output only"), then configure the Log file name field.
When defining your path, use the & parameter prefix to automatically inject real-time session metadata into the filename.
Supported Substitution Variables
| Variable | Replacement Description | Example Output |
|---|---|---|
&H |
Target Host Name / IP Address | web01.example.internal |
&P |
Destination Port Number | 22 |
&Y |
Current Year (4 digits) | 2026 |
&M |
Current Month (2 digits) | 08 |
&D |
Current Day of Month (2 digits) | 31 |
&T |
Current Time (6 digits: HHMMSS) |
143015 |
Practical Path Examples
1. Standard Host and Timestamp Template
To organize session captures by target server name and full timestamp, enter the following pattern in the Log file name box:
C:\puttylogs\&H_&Y-&M-&D_&T.log
PuTTY automatically resolves this into clean, chronological log files:
C:\puttylogs\srv-db01.internal_2026-08-31_125405.log
C:\puttylogs\192.168.1.10_2026-08-31_130522.log
2. Dedicated Port and Daily File Naming
If connecting to non-standard ports or consolidating daily sessions into one log per host:
C:\puttylogs\&H_port&P_&Y&M&D.log
Best Practice: Saving to Default Settings
To ensure every future connection is logged automatically without setting this per profile:
- Open PuTTY and go to Session > Logging.
- Set the desired logging method and dynamic file path.
- Select "Always append to the end of it" under What to do if the log file already exists.
- Click back to Session in the left pane, click Default Settings, and hit Save.
No comments:
Post a Comment