How to export/import PuTTy sessions list?

后端 未结 15 1184
时光取名叫无心
时光取名叫无心 2020-12-22 14:41

Is there a way to do this?

Or I have to take manually every record from Registry?

相关标签:
15条回答
  • 2020-12-22 14:45

    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!

    0 讨论(0)
  • 2020-12-22 14:49

    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"
    
    0 讨论(0)
  • 2020-12-22 14:49

    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

    0 讨论(0)
  • 2020-12-22 14:53

    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

    0 讨论(0)
  • 2020-12-22 14:55

    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.

    0 讨论(0)
  • 2020-12-22 14:56

    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.

    0 讨论(0)
提交回复
热议问题