Skip to content

Instantly share code, notes, and snippets.

@ezr
Created March 24, 2020 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezr/0f8bf75a821b408d9c505f44f09563fa to your computer and use it in GitHub Desktop.
Save ezr/0f8bf75a821b408d9c505f44f09563fa to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
from glob import glob
import os
session_files = glob(os.environ["HOME"] + "/.putty/sessions/*")
out_file = open("putty-sessions.reg", "w")
header = '''Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions]
'''
out_file.write(header)
for fpath in session_files:
f = open(fpath, "r")
lines = f.readlines()
fname = fpath.split('/')[-1]
out_file.write("\n[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\%s]\n" % fname)
for line in lines:
data = line.split("=")
key = data[0]
val = data[1].strip()
out_file.write("\"%s\"=" % key)
try:
int(val)
out_file.write("dword:%s\n" % val.zfill(8))
except:
out_file.write("\"%s\"\n" % val)
f.close()
out_file.close()
@ezr
Copy link
Author

ezr commented Mar 24, 2020

This is a python script that you can run on a linux system whose putty sessions are saved under ~/.putty/sessions/. The purpose is to migrate the info into a .reg file which can be imported on windows.

Very lightly tested. USE AT YOUR OWN RISK. If anyone attempts to use this then make sure to back up the registry keys on windows before making any changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment