首页 文章

如何导出/导入PuTTy会话列表?

提问于
浏览
531

有没有办法做到这一点?

或者我必须手动从Registry中获取每条记录?

14 回答

  • 6
    • 启动运行,然后在打开下拉窗口中输入:regedit

    • 导航到,就像在Window的资源管理器中一样:
      HKEY_CURRENT_USER \ SOFTWARE \ SimonTatham

    • 右键单击'SimonTatham'键(目录图标),选择“导出”
      为文件命名(例如)putty.reg并将其保存到您的位置
      以后用 .

    • 关闭注册表编辑器 .

    完成 .

  • 985

    出口

    cmd.exe,需要提升提示:

    只有 Session :

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

    所有设置:

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

    Powershell:

    只有 Session :

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

    所有设置:

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

    导入

    双击 *.reg 文件并接受导入 .

    替代方式:

    cmd.exe,需要提升的命令提示符:

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

    PowerShell:

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

    注意: do not replace SimonTatham 与您的用户名 .

    注意:它将在当前用户的桌面上创建 reg 文件 .

    注意:它将 not 导出相关的SSH密钥 .

  • 6

    当我尝试其他解决方案时,我收到此错误:

    Registry editing has been disabled by your administrator.
    

    Phooey,我说!

    我将以下powershell脚本放在一起,用于导出和导入PuTTY设置 . 导出的文件是一个windows .reg文件,如果您有权限将导入干净,否则使用import.ps1加载它 .

    Warning :像这样捣乱注册表是一个坏主意™,我不会这样做 . 使用以下脚本需要您自担风险,并准备好让您的IT部门重新映像您的计算机并向您询问有关您正在做什么的不舒服的问题 .

    在源机器上:

    .\export.ps1
    

    在目标机器上:

    .\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"
    

    对于非惯用代码的道歉,我对Powershell并不是很熟悉 . 欢迎改进!

  • 37

    如果要在 PuTTY Portable 上导入设置,可以使用 putty.reg 文件 .

    把它放到这条路径 [path_to_Your_portable_apps]PuTTYPortable\Data\settings\putty.reg . 程序将导入它

  • 34

    对于那些需要从离线注册表文件中导入Putty的人,例如当您从崩溃的系统中恢复或只是移动到新机器并从旧驱动器中获取数据时,还有一个值得一提的解决方案:

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

    这个优秀的免费控制台应用程序将导出整个注册表或仅导出特定的注册表项 . 在我的情况下,我只是将注册表文件从旧驱动器复制到与导出工具相同的目录,然后我在CMD窗口中使用以下命令和语法作为管理员运行:

    RegFileExport.exe NTUSER.DAT putty.reg“HKEY_CURRENT_USER \ Software \ SimonTatham”

    导入.reg文件并启动Putty后,一切都在那里 . 简单高效 .

  • 2

    导入注册表导出比上面说的容易得多 . 只是:

    • 右键单击文件并

    • 选择"Merge"

    在Win 7 Pro上像冠军一样工作 .

  • 31

    对于那些不想弄乱注册表的人,已经创建了一个保存到文件的putty变体 . 它位于:http://jakub.kotrla.net/putty/

    如果腻子团队将其作为主要发行版的一个选项,那将是很好的 .

  • 10

    bumerang解决方案的改进,以将数据导入 PuTTY portable .

    只需将导出的 putty.reg (使用m0nhawk解决方案)移动到 PuTTYPortable\Data\settings\ 就不起作用了 . PuTTY Portable备份文件并创建一个新的空文件 .

    要解决此问题,请同时合并 putty.reg 将要导出的配置从导出的 putty.reg 复制到下面行中新创建的 PuTTYPortable\Data\settings\putty.reg .

    REGEDIT4
    
    [HKEY_CURRENT_USER\Software\SimonTatham\PuTTY]
    "RandSeedFile"="D:\\Programme\\PuTTYPortable\\Data\\settings\\PUTTY.RND"
    
  • 6

    Example:
    如何将putty配置和会话配置从一个用户帐户转移到另一个用户帐户,例如创建新帐户并希望使用旧帐户中的putty会话/配置时

    Process:

    • 将旧帐户的注册表项导出到文件中
    • 将注册表项从文件导入新帐户

    Export reg key: (来自OLD账户)

    • 登录OLD帐户,例如做成模子

    • 打开正常'command prompt'(不是管理员!)

    • 类型'regedit'

    • 导航到存储配置的注册表部分,例如[HKEY_CURRENT_USER \ SOFTWARE \ SimonTatham]并点击它

    • 从文件菜单中选择'Export'或单击鼠标右键(radio ctrl 'selected branch')

    • 保存到文件中并为其命名,例如'puttyconfig.reg'

    • 再次退出

    Import reg key: (进入新帐户)

    • 登录新帐户,例如汤姆

    • 打开正常的'命令提示符'(不是管理员!)

    • 输入'regedit'

    • 从菜单中选择“导入”

    • 选择要导入的注册表文件,例如'puttyconfig.reg'

    • 完成

    Note:
    不要使用'admin command prompt',因为设置位于'[HKEY_CURRENT_USER...] '下,regedit将以管理员身份运行,并显示admin-user的部分,而不是用户从和/或转移到 .

  • 11

    由于我在Windows 7机器上进行测试,@ m0nhawk发布的答案似乎不起作用 . 相反,使用以下脚本导出/导入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
    
  • 2

    使用此方法还可以执行批量配置更改,例如更改所有会话字体 .

    • 导出到.reg

    • 执行搜索并替换.reg

    • 删除所有会话

    • 导入新的.reg

    从这里提取:http://www.sysadmit.com/2015/11/putty-exportar-configuracion.html

  • 17

    m0nhawk的回答在Windows 10上对我不起作用 - 它需要提升命令提示符并拒绝发出文件 .

    这有效,不需要提升:

    reg export HKEY_CURRENT_USER\Software\SimonTatham\PuTTY putty.reg
    
  • 8

    我使用putty connection manager创建会话数据库 . 将数据库复制并导入其他计算机很容易 .

    看到这个handy guide

  • 9

    ratil.life/first-useful-powershell-script-putty-to-ssh-config上有一个PowerShell脚本,可以将会话转换为可以在 .ssh/config 中使用的格式 . 它也可以在GitHub找到 .

    这段摘录包含代码的主要内容,并将生成的配置直接打印到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 }
        }
    
    }
    

相关问题