725

Is there a way to do this?

Or I have to take manually every record from Registry?

kenorb
  • 118,428
  • 63
  • 588
  • 624
s.webbandit
  • 15,198
  • 14
  • 53
  • 79

15 Answers15

1340

Export

cmd.exe, require elevated prompt:

Only sessions:

regedit /e "%USERPROFILE%\Desktop\putty-sessions.reg" HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions

All settings:

regedit /e "%USERPROFILE%\Desktop\putty.reg" HKEY_CURRENT_USER\Software\SimonTatham

Powershell:

Only sessions:

reg export HKCU\Software\SimonTatham\PuTTY\Sessions ([Environment]::GetFolderPath("Desktop") + "\putty-sessions.reg")

All settings:

reg export HKCU\Software\SimonTatham ([Environment]::GetFolderPath("Desktop") + "\putty.reg")

Import

Double-click on the *.reg file and accept the import.

Alternative ways:

cmd.exe, require elevated command prompt:

regedit /i putty-sessions.reg
regedit /i putty.reg

PowerShell:

reg import putty-sessions.reg
reg import putty.reg

Note: do not replace SimonTatham with your username.

Note: It will create a reg file on the Desktop of the current user.

Note: It will not export related SSH keys.

m0nhawk
  • 20,919
  • 9
  • 39
  • 68
  • I got the error as snapshot here - how to get over it? https://www.dropbox.com/s/om426f8gen9mhxs/how-to-export-putty-sessions-list.png?dl=0 – Nam G VU Jan 08 '15 at 03:15
  • 3
    @NamGVU That's because path have a folder with spaces. Move to one that didn't have it. – m0nhawk Jan 08 '15 at 19:05
  • I tried with no space in export path and the error remains though. – Nam G VU Jan 10 '15 at 06:45
  • 3
    @NamGVU Do not replace %userprofile% with your username, leave it as is. – Asrar Feb 09 '15 at 14:24
  • Thanks Asrar. I'll try that – Nam G VU Feb 09 '15 at 23:21
  • 7
    Second Command worked for me on Windows 7, however, I needed to run CMD as administrator. – The Humble Rat Oct 16 '15 at 07:36
  • Ran the 1st command from Run rather than cmd and got file 'putty-sessions.reg' on desktop (Win7). – Aniket Thakur Jun 20 '16 at 11:09
  • I was inspired by your answer to help sleske : http://serverfault.com/a/745968/329412 – Nolwennig Aug 11 '16 at 07:28
  • I'm getting nothing on Windows 10 – Maria Ines Parnisari Sep 03 '16 at 19:13
  • @mparnisari Check your Desktop. It should create a `.reg` file there with all the settings. – m0nhawk Sep 04 '16 at 05:37
  • 1
    This worked for me moving this from Windows 7 to Windows 10, but I had to run regedit as myself and use the Import feature there. Otherwise, just trying to import the .reg file itself on the new computer imported the settings to the Administrative user instead. – Mark Nov 01 '16 at 13:25
  • I tried this and did not get any file. I searched the registry and there was no key named 'SimonTatham'. This is with putty version 0.62 with Windows 7. – Larry Martell Dec 03 '16 at 16:30
  • To import, I opened the pc where I wanted to import the putty info. windows start button->run regedit->File->Import and import the each .reg file respectively. – Miles Jan 03 '17 at 18:39
  • This does not seem to work the way that I expected. My group works with around 50 hosts which I have saved sessions for in Pageant/PuTTy. The export method above creates a file, but when I look at it using Edit, I do not see any of host names or addresses. Just options stuff like color, terminal type, etc. Am I missing something or misunderstanding what this is suppose to do? Thanks. – Scott Law May 17 '17 at 13:23
  • @ScottLaw The first command will export only the sessions, still they will have other options, like color, fonts etc. Try searching `HostName`, for example. – m0nhawk May 17 '17 at 16:43
  • @m0nhawk: No, it just wasn't there. Looking at the GUI version, I suddenly woke up to the fact that both the folders under sessions were from an older project that I was on, neither of which were in my current saved sessions. I did a search for one of my current hostnames through the whole registry and found a pile in HKEY_USERS in some Microsoft package and it contained basically every one that I have ever saved included my current stack. Right click and save that sessions folder and I think I am good now. Thanks for your time. – Scott Law May 17 '17 at 19:44
  • Though if you go this route and are trying to provide a resource for new users, I would suggest editing the exported file to replace all occurrences of the path (mine was buried way down in HKEY_USERS) with HKEY_CURRENT_USER. Also also have the new user replace all your username references with their own before importing. – Scott Law May 17 '17 at 20:02
  • export worked to one computer but not in another (couldn't find the reg file), why? Both were similar with same OS (Win10) – Yannis Dran Sep 08 '17 at 11:12
  • 1
    As far as I know you don't need elevated command prompt when you export from branch `HKEY_CURRENT_USER\...`. Elevated rights are required only for `HKEY_LOCAL_MACHINE`, `HKEY_CLASSES_ROOT`, etc. – Wernfried Domscheit Nov 15 '18 at 21:42
  • 1
    If it is PuTTy 64, it is in `HKEY_LOCAL_MACHINE\SOFTWARE\SimonTatham\PuTTY64`. – WesternGun Feb 17 '19 at 11:04
  • Some putty installs on Windows (and every install on Linux) do not use the registry, mind how you go. – mckenzm Aug 02 '19 at 01:00
55

When I tried the other solutions I got this error:

Registry editing has been disabled by your administrator.

Phooey to that, I say!

I put together the below powershell scripts for exporting and importing PuTTY settings. The exported file is a windows .reg file and will import cleanly if you have permission, otherwise use import.ps1 to load it.

Warning: messing with the registry like this is a Bad Idea™, and I don't really know what I'm doing. Use the below scripts at your own risk, and be prepared to have your IT department re-image your machine and ask you uncomfortable questions about what you were doing.

On the source machine:

.\export.ps1

On the target machine:

.\import.ps1 > cmd.ps1
# Examine cmd.ps1 to ensure it doesn't do anything nasty
.\cmd.ps1

export.ps1

# All settings
$registry_path = "HKCU:\Software\SimonTatham"
# Only sessions
#$registry_path = "HKCU:\Software\SimonTatham\PuTTY\Sessions"
$output_file = "putty.reg"

$registry = ls "$registry_path" -Recurse

"Windows Registry Editor Version 5.00" | Out-File putty.reg
"" | Out-File putty.reg -Append

foreach ($reg in $registry) {
  "[$reg]" | Out-File putty.reg -Append
  foreach ($prop in $reg.property) {
    $propval = $reg.GetValue($prop)
    if ("".GetType().Equals($propval.GetType())) {
      '"' + "$prop" + '"' + "=" + '"' + "$propval" + '"' | Out-File putty.reg -Append
    } elseif ($propval -is [int]) {
      $hex = "{0:x8}" -f $propval
      '"' + "$prop" + '"' + "=dword:" + $hex | Out-File putty.reg -Append
    }
  }
  "" | Out-File putty.reg -Append
}

import.ps1

$input_file = "putty.reg"

$content = Get-Content "$input_file"

"Push-Location"
"cd HKCU:\"

foreach ($line in $content) { 
  If ($line.StartsWith("Windows Registry Editor")) {
    # Ignore the header
  } ElseIf ($line.startswith("[")) {
    $section = $line.Trim().Trim('[', ']')
    'New-Item -Path "' + $section + '" -Force' | %{ $_ -replace 'HKEY_CURRENT_USER\\', '' }
  } ElseIf ($line.startswith('"')) {
    $linesplit = $line.split('=', 2)
    $key = $linesplit[0].Trim('"')
    if ($linesplit[1].StartsWith('"')) {
      $value = $linesplit[1].Trim().Trim('"')
    } ElseIf ($linesplit[1].StartsWith('dword:')) {
      $value = [Int32]('0x' + $linesplit[1].Trim().Split(':', 2)[1])
      'New-ItemProperty "' + $section + '" "' + $key + '" -PropertyType dword -Force' | %{ $_ -replace 'HKEY_CURRENT_USER\\', '' }
    } Else {
      Write-Host "Error: unknown property type: $linesplit[1]"
      exit
    }
    'Set-ItemProperty -Path "' + $section + '" -Name "' + $key + '" -Value "' + $value + '"' | %{ $_ -replace 'HKEY_CURRENT_USER\\', '' }
  }
}

"Pop-Location"

Apologies for the non-idiomatic code, I'm not very familiar with Powershell. Improvements are welcome!

dwurf
  • 11,185
  • 5
  • 26
  • 38
  • 3
    Worked perfectly, what a time-saver. One addition ... I had to follow instructions here to setup permissions: http://stackoverflow.com/questions/4037939/powershell-says-execution-of-scripts-is-disabled-on-this-system. – Jacob Zwiers May 25 '15 at 17:04
  • 1
    That was a great help! I had different registry locations just had to edit the path in both and that was it :) – SidJ May 17 '17 at 03:29
  • 1
    Wait, so PowerShell circumvents group policy? Wonder how long until _that_ gets patched. – Quolonel Questions Jun 20 '19 at 18:43
  • 1
    Not sure, but we're at four years and counting ;) – dwurf Jun 21 '19 at 06:51
  • This bug, fortunately, does not seem to be present in Windows 10 1909. Using New-Item as a regular user on the Registry PSProvider now throws a System.UnauthorizedAccessException – Rainmaker Jun 22 '20 at 11:11
  • 2
    PuTTY is a program that can edit your registry. If they "patch" your permissions so user-runnable programs can't edit the registry you won't have any PuTTY settings to export. – LinuxDisciple Sep 16 '20 at 00:03
  • The import script did not work for me, but I was able to just open regedit and import the exported file. – runrig Mar 25 '21 at 20:49
49
  1. Launch Run, then type in the Open drop down window: regedit

  2. Navigate to, just like in Window's Explorer:
    HKEY_CURRENT_USER\Software\SimonTatham

  3. Right click on 'SimonTatham' key (directory icon), select Export
    Give the file a name (say) putty.reg and save it to your location for
    later use.
  4. Close Registry Editor.

Done.

Sireesh Yarlagadda
  • 10,572
  • 2
  • 65
  • 71
  • 1
    After export, copy that .reg file to the computer that you want to use those setting. Simply double click it to take effect. – admin Oct 27 '20 at 07:57
36

If You want to import settings on PuTTY Portable You can use the putty.reg file.

Just put it to this path [path_to_Your_portable_apps]PuTTYPortable\Data\settings\putty.reg. Program will import it

bumerang
  • 1,636
  • 19
  • 29
25

For those of you who need to import Putty from offline registry file e.g. when you are recovering from crashed system or simply moving to a new machine and grabbing data off that old drive there is one more solution worth mentioning:

http://www.nirsoft.net/utils/registry_file_offline_export.html

This great and free console application will export the entire registry or only a specific registry key. In my case i simply copied the registry file from an old drive to the same directory as the exporter tool and then i used following command and syntax in CMD window run as administrator:

RegFileExport.exe NTUSER.DAT putty.reg "HKEY_CURRENT_USER\Software\SimonTatham"

After importing the .reg file and starting Putty everything was there. Simple and efficient.

monsune
  • 359
  • 3
  • 4
  • 2
    This answer is narrow enough of a use case to be included in a separate question for offline recovery. Thanks. – Frank Phillips Oct 13 '16 at 13:32
  • 5
    I would add a note that the NTUSER.DAT is located in Users/[Username] as a protected system file, and not in Windows/SYSTEM32/Config. – Frank Phillips Oct 13 '16 at 13:36
15

For those who don't want to mess with the registry, a variation of putty that saves to file has been created. It is located here: http://jakub.kotrla.net/putty/

It would be nice if the putty team would take this as an option into the main distribution.

Jason K.
  • 532
  • 12
  • 18
13

This was so much easier importing the registry export than what is stated above. + Simply:

  1. right click on the file and
  2. select "Merge"

Worked like a champ on Win 7 Pro.

davejal
  • 5,431
  • 10
  • 33
  • 73
DudeGoingDeaf
  • 131
  • 1
  • 3
11

Example:
How to transfer putty configuration and session configuration from one user account to another e.g. when created a new account and want to use the putty sessions/configurations from the old account

Process:
- Export registry key from old account into a file
- Import registry key from file into new account

Export reg key: (from OLD account)

  1. Login into the OLD account e.g. tomold
  2. Open normal 'command prompt' (NOT admin !)
  3. Type 'regedit'
  4. Navigate to registry section where the configuration is being stored e.g. [HKEY_CURRENT_USER\SOFTWARE\SimonTatham] and click on it
  5. Select 'Export' from the file menu or right mouse click (radio ctrl 'selected branch')
  6. Save into file and name it e.g. 'puttyconfig.reg'
  7. Logout again

Import reg key: (into NEW account)

  1. Login into NEW account e.g. tom

  2. Open normal 'command prompt' (NOT admin !)

  3. Type 'regedit'

  4. Select 'Import' from the menu

  5. Select the registry file to import e.g. 'puttyconfig.reg'

  6. Done

Note:
Do not use an 'admin command prompt' as settings are located under '[HKEY_CURRENT_USER...] 'and regedit would run as admin and show that section for the admin-user rather then for the user to transfer from and/or to.

Mungo
  • 111
  • 1
  • 4
10

An improvement to the solution of bumerang to import data to PuTTY portable.

Simply moving exported putty.reg (with m0nhawk solution) to PuTTYPortable\Data\settings\ didn't work. PuTTY Portable backup the file and create a new empty one.

To workaround this issue, merge both putty.reg copying manually the config you want to migrate from your exported putty.reg to the newly created PuTTYPortable\Data\settings\putty.reg below following lines.

REGEDIT4

[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY]
"RandSeedFile"="D:\\Programme\\PuTTYPortable\\Data\\settings\\PUTTY.RND"
L. G.
  • 9,087
  • 7
  • 47
  • 73
10

m0nhawk's answer didn't work for me on Windows 10 - it required elevated command prompt and refused to emit a file.

This worked and didn't require elevation:

reg export HKEY_CURRENT_USER\Software\SimonTatham\PuTTY putty.reg
fiat
  • 13,753
  • 6
  • 72
  • 94
8

The answer posted by @m0nhawk doesn't seem to work as I test on a Windows 7 machine. Instead, using the following scripts would export/import the settings of putty:

::export
@echo off
set regfile=putty.reg
pushd %~dp0

reg export HKCU\Software\SimonTatham %regfile% /y

popd

--

::import
@echo off
pushd %~dp0
set regfile=putty.reg

if exist %regfile% reg import %regfile%

popd
Meow
  • 3,455
  • 1
  • 16
  • 16
6

Using this method it is also possible to perform mass configuration changes, such as changing the all sessions font.

  1. Export to .reg
  2. Perform a search and replace over .reg
  3. Remove all sessions
  4. Import the new .reg

Extracted from here: http://www.sysadmit.com/2015/11/putty-exportar-configuracion.html

Tunaki
  • 116,530
  • 39
  • 281
  • 370
YumUrli
  • 61
  • 1
  • 1
5

If you, like me, installed new Windows and only after you remember about putty sessions, you can still import them, if you have old Windows hard drive or at least your old "home" directory backed up (C:\Users\<user_name>).

In this directory there should be NTUSER.DAT file. It is hidden by default, so you should enable hidden files in your Windows explorer or use another file browser. This file contains the HKEY_CURRENT_USER branch of your old Windows registry.

To use it, you need to open regedit on your new Windows, and select HKEY_USERS key.

Then select File -> Load Hive... and find your old "home" directory of your old Windows installation. In this directory there should be NTUSER.DAT file. It is hidden by default, so, if you didn't enable to show hidden files in your Windows explorer properties, then you can just manually enter file name into File name input box of "Load Hive" dialog and press Enter. Then in the next dialog window enter some key name to load old registry into it. e.g. tmp.

Your old registry's HKEY_CURRENT_USER branch now should be accessible under HKEY_USERS\tmp branch of your current registry.

Now export HKEY_USERS\tmp\Software\SimonTatham branch into putty.reg file, open this file in your favorite text editor and find-and-replace all HKEY_USERS\tmp string with HKEY_CURRENT_USER. Now save the .reg file.

You can import now this file into your current Windows registry by double-clicking it. See m0nhawk's answer how to do this.

In the end, select HKEY_USERS\tmp branch in the registry editor and then select File -> Unload Hive... and confirm this operation.

Ruslan Stelmachenko
  • 3,746
  • 28
  • 43
  • 1
    This answer along with https://superuser.com/a/1370670/1198855 helped me to solve the problem. I had an error while loading the hive for some reason. Thanks! – stackunderflow Jul 16 '20 at 20:11
4

There is a PowerShell script at ratil.life/first-useful-powershell-script-putty-to-ssh-config which can convert the sessions to a format that can be used in .ssh/config. It can also be found on GitHub.

This excerpt contains the main guts of the code, and will print the resulting config directly to stdout:

# Registry path to PuTTY configured profiles
$regPath = 'HKCU:\SOFTWARE\SimonTatham\PuTTY\Sessions'

# Iterate over each PuTTY profile
Get-ChildItem $regPath -Name | ForEach-Object {

    # Check if SSH config
    if (((Get-ItemProperty -Path "$regPath\$_").Protocol) -eq 'ssh') {
        # Write the Host for easy SSH use
        $host_nospace = $_.replace('%20', $SpaceChar)
        $hostLine =  "Host $host_nospace"

        # Parse Hostname for special use cases (Bastion) to create SSH hostname
        $puttyHostname = (Get-ItemProperty -Path "$regPath\$_").HostName
        if ($puttyHostname -like '*@*') {
            $sshHostname = $puttyHostname.split("@")[-1]
            }
        else { $sshHostname = $puttyHostname }
        $hostnameLine = "`tHostName $sshHostname"   

        # Parse Hostname for special cases (Bastion) to create User
        if ($puttyHostname -like '*@*') {
            $sshUser = $puttyHostname.split("@")[0..($puttyHostname.split('@').length - 2)] -join '@'
            }
        else { $sshHostname = $puttyHostname }
        $userLine = "`tUser $sshUser"   

        # Parse for Identity File
        $puttyKeyfile = (Get-ItemProperty -Path "$regPath\$_").PublicKeyFile
        if ($puttyKeyfile) { 
            $sshKeyfile = $puttyKeyfile.replace('\', '/')
            if ($prefix) { $sshKeyfile = $sshKeyfile.replace('C:', $prefix) }
            $identityLine = "`tIdentityFile $sshKeyfile"
            }

        # Parse Configured Tunnels
        $puttyTunnels = (Get-ItemProperty -Path "$regPath\$_").PortForwardings
        if ($puttyTunnels) {
            $puttyTunnels.split() | ForEach-Object {

                # First character denotes tunnel type
                $tunnelType = $_.Substring(0,1)
                # Digits follow tunnel type is local port
                $tunnelPort = $_ -match '\d*\d(?==)' | Foreach {$Matches[0]}
                # Text after '=' is the tunnel destination
                $tunnelDest = $_.split('=')[1]

                if ($tunnelType -eq 'D') {
                    $tunnelLine = "`tDynamicForward $tunnelPort $tunnelDest"
                }

                ElseIf ($tunnelType -eq 'R') {
                    $tunnelLine = "`tRemoteForward $tunnelPort $tunnelDest"
                }

                ElseIf ($tunnelType -eq 'L') {
                    $tunnelLine = "`tLocalForward $tunnelPort $tunnelDest"
                }

            }

        # Parse if Forward Agent is required
        $puttyAgent = (Get-ItemProperty -Path "$regPath\$_").AgentFwd
        if ($puttyAgent -eq 1) { $agentLine = "`tForwardAgent yes" }

        # Parse if non-default port
        $puttyPort = (Get-ItemProperty -Path "$regPath\$_").PortNumber
        if (-Not $puttyPort -eq 22) { $PortLine = "`tPort $puttyPort" }

        }

        # Build output string
        $output = "$hostLine`n$hostnameLine`n$userLine`n$identityLine`n$tunnelLine`n$agentLine`n"

        # Output to file if set, otherwise STDOUT
        if ($outfile) { $output | Out-File $outfile -Append}
        else { Write-Host $output }
    }

}
mwfearnley
  • 2,377
  • 1
  • 27
  • 29
3

I use putty connection manager where you create a database of sessions. It's easy to copy and import that database to other computers.

See this handy guide

jasonoriordan
  • 823
  • 16
  • 24