Thursday, July 18, 2013

Yet Another way to Fix PuTTY Color Defaults

A quick web search will reveal that many people who use PuTTY as an SSH client are _not_ particularly fond of the default colors.  Count me amongst those who find it nearly impossible to read dark blue text on a black background.  For years I've just used the PuTTY settings dialog window to edit the colors (or Colours as they're named in the registry settings).  As the number of saved sessions I have has grown, it has become less and less practical to go fix the colors individually, so I cooked up a different way to reset all the sessions in one action.

The Colour settings are stored for each PuTTY session in the registry keys (each named after the session) under the key


I've seen other posts that suggest fixing the default colors by running a .reg file to create a new session with the desired colors but that doesn't help if you've got dozens of sessions that have the wrong (I mean default) color settings already.

Since Putty runs on Windows, the tool that made the most sense to help fix it is an add-on, techie utility from Microsoft called PowerShell.  PowerShell makes it reasonably easy to perform useful "extra" stuff like listing and modifying specific registry keys.  Without getting into a full PowerShell tutorial, which you can find at Microsoft's Technet Site if you like, I'll just skip to the how-to instructions.  Before you do any of this, as everyone else always warns, this modifies the Windows registry, so you should make a backup, buy a spare computer, print out all your photos on archival paper, create a rescue disk, retain the services of at least two system recovery experts, etc. etc... So you've been warned, and it's 100% your responsibility if you screw something up, even if I made some mistake writing this.
  1. Download PowerShell (any version) from Microsoft's web site, and install it.
  2. Run PowerShell from a command prompt (assuming if you use PuTTY, you'd be comfortable with this).
  3. Enter the PowerShell cmdlet Set-ExecutionPolicy Unrestricted (so you can run your own unsigned scripts) See:
  4. Save the script code below into a file named "fix-putty-colors.ps1"  (to most people, it should be reasonably obvious what the script does).
  5. Execute the script from within PowerShell
  6. Enter the PowerShell cmdlet Set-ExecutionPolicy Restricted  (this is optional but for those who are in the paranoid-about-security camp, it makes it slightly harder for a rogue script to run accidentally after you've finished fixing the PuTTY registry settings).

Script Code (modify to set other color codes and/or add other color properties if desired):

Set-Location 'HKCU:\Software\SimonTatham\PuTTY\Sessions'
Get-ChildItem |
ForEach-Object {
   Set-Location Registry::$_
   Set-ItemProperty -Path . -Name Colour14 -Value '150,150,187'
   Set-ItemProperty -Path . -Name Colour15 -Value '200,200,255'

No comments: