## How to Configure PuTTY’s Log File

PuTTY doesn’t seem to have a command-line way of turning on logging and specifying a log file in which to output session data. That’s rather annoying, but there is a workaround. This information is stored in the Windows Registry for the Default Session. So if you edit the LogFileName string and LogFileType DWORD values for the Default Session key, you can specify the log file without having to use the GUI. This is helpful in unattended scenarios.

The path to the key is:
HKEY_CURRENT_USER
\Software
\SimonTatham
\PuTTY
\Sessions
\Default%20Settings

The best part is: If you only create the LogFileName string and LogFileType DWORD values, PuTTY will create the rest later. This means you don’t have to create the complete key which contains dozens of different values.

You can use the Windows Registry Editor (the regedit command) to navigate your way to the proper key and create the values. Note that none of the keys will exist if PuTTY has not been run before.

If you want to do it in a completely unattended manner, you can save the values to a .reg file and use the reg import command. Save the text below to a text file named, for example, putty_settings.reg

Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\Default%20Settings]
"LogFileName"="..\\up\\and\\over\\to\\mylogfile.log"
"LogType"=dword:00000002


Then import it using the command below.

reg import putty_settings.reg


Tips

• The reg import command is very picky about formatting. Make sure the first line of the .reg file is exactly as shown above.
• Backslashes need to be doubled. For example, ..\up\and\over needs to be typed as ..\\up\\and\\over
• I found that All session output is 2, so I set LogType to 2 in the registry. I did not test any other values.

Below is a screenshot of PuTTY before the registry key

Below is a screenshot of PuTTY after the registry key

### 8 Responses to “How to Configure PuTTY’s Log File”

1. sanjeev says:

how to make append to it automatically without prompt?

whew… I wrote this 2.5 years ago. Since then, we’ve migrated away from Windows and are using Red Hat Linux. I do remember this working, though.

I don’t recall any prompts… This was intended to be run unattended without user input.

This was used to run a script on a Windows server, SSH into a Linux server, run another script, and retrieve the result.

3. Giovanni says:

Thanks again!
This information was perfect and useful also with Windows 7 x64!

4. chok says:

Putty runs on Linux also – I use it under Debian. I like it creating it’s own window instead of taking up a shell prompt window. These same settings are saved in ~/.putty/sessions and of course, you can just use your favorite editor.

5. John says:

Thanks for pointing that out.

I didn’t know PuTTY runs on Linux, but it makes sense that it would be OS-independent. With Linux, you can just
ssh someone@somewhere.com < my_script > results.txt

That’s all I was trying to accomplish with this blog post… Write a script to SSH from a Windows machine to a Linux machine, run my_script, and process whatever was sent to standard output.

6. tony balleras says:

thanks man. never thought this was possible.

tonyb

7. RHP-997 says:

The LogType value for the “Printable output” setting is 1

8. Ian says:

You can also save speed and space with the choice of an automatic “Log file name”, eg.:
\Logs\&Y-&M_Putty.log (or even \Logs\&Y-&M-&D_Putty.log)
and remember to choose also the “Always append to the end of it” option (you can also use &T for the time and &H for the name of the host).
Doing so you’ll obtain a different detailed and incremental log file for every month (or day) that you can subsequently compress it monthly (or daily) to save space, if your logs are very huge like mine.