How to export/import PuTTY sessions list?

WindowsRegistryPutty

Windows Problem Overview


Is there a way to do this?

Or I have to take manually every record from Registry?

Windows Solutions


Solution 1 - Windows

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.

Solution 2 - Windows

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!

Solution 3 - Windows

  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.

Solution 4 - Windows

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

Solution 5 - Windows

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.

Solution 6 - Windows

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.

Solution 7 - Windows

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.

Solution 8 - Windows

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

Solution 9 - Windows

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.

Solution 10 - Windows

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"

Solution 11 - Windows

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

Solution 12 - Windows

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.

Solution 13 - Windows

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

Solution 14 - Windows

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 }
    }
   
}

Solution 15 - Windows

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questions.webbanditView Question on Stackoverflow
Solution 1 - Windowsm0nhawkView Answer on Stackoverflow
Solution 2 - WindowsdwurfView Answer on Stackoverflow
Solution 3 - WindowsSireesh YarlagaddaView Answer on Stackoverflow
Solution 4 - WindowsbumerangView Answer on Stackoverflow
Solution 5 - WindowsmonsuneView Answer on Stackoverflow
Solution 6 - WindowsJason K.View Answer on Stackoverflow
Solution 7 - WindowsDudeGoingDeafView Answer on Stackoverflow
Solution 8 - WindowsfiatView Answer on Stackoverflow
Solution 9 - WindowsMungoView Answer on Stackoverflow
Solution 10 - WindowsL. G.View Answer on Stackoverflow
Solution 11 - WindowsMeowView Answer on Stackoverflow
Solution 12 - WindowsRuslan StelmachenkoView Answer on Stackoverflow
Solution 13 - WindowsYumUrliView Answer on Stackoverflow
Solution 14 - WindowsmwfearnleyView Answer on Stackoverflow
Solution 15 - WindowsjasonoriordanView Answer on Stackoverflow