【发布时间】:2012-10-13 00:00:00
【问题描述】:
有没有办法做到这一点?
或者我必须手动从注册表中获取每条记录?
【问题讨论】:
有没有办法做到这一点?
或者我必须手动从注册表中获取每条记录?
【问题讨论】:
如果您像我一样安装了新的 Windows,并且仅在您记得有关 putty 会话之后,您仍然可以导入它们,如果您有旧的 Windows 硬盘驱动器或至少是旧的“主”目录已备份 (C:\Users\<user_name>)。
在这个目录下应该有NTUSER.DAT 文件。默认情况下它是隐藏的,因此您应该在 Windows 资源管理器中启用隐藏文件或使用其他文件浏览器。此文件包含旧 Windows 注册表的 HKEY_CURRENT_USER 分支。
要使用它,你需要在你的新Windows上打开regedit,然后选择HKEY_USERS键。
然后选择 File -> Load Hive... 并找到旧 Windows 安装的旧“主”目录。在这个目录中应该有NTUSER.DAT 文件。默认情况下它是隐藏的,因此,如果您没有在 Windows 资源管理器属性中启用显示隐藏文件,那么您可以手动在“Load Hive”对话框的File name 输入框中输入文件名,然后按 Enter 。然后在下一个对话框窗口中输入一些键名以将旧注册表加载到其中。例如tmp.
您的旧注册表的HKEY_CURRENT_USER 分支现在应该可以在您当前注册表的HKEY_USERS\tmp 分支下访问。
现在将HKEY_USERS\tmp\Software\SimonTatham 分支导出到putty.reg 文件中,在您喜欢的文本编辑器中打开此文件,然后将所有HKEY_USERS\tmp 字符串查找并替换为HKEY_CURRENT_USER。现在保存.reg 文件。
您现在可以通过双击此文件将其导入当前的 Windows 注册表。请参阅m0nhawk's answer 如何执行此操作。
最后在注册表编辑器中选择HKEY_USERS\tmp分支,然后选择File -> Unload Hive...并确认此操作。
【讨论】:
ratil.life/first-useful-powershell-script-putty-to-ssh-config 有一个 PowerShell 脚本,可以将会话转换为可在.ssh/config 中使用的格式。也可以在GitHub找到。
这段摘录包含代码的主要内容,并将生成的配置直接打印到标准输出:
# 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 }
}
}
【讨论】:
启动运行, 然后在打开下拉窗口中输入:regedit
导航到,就像在 Window 的资源管理器中一样:
HKEY_CURRENT_USER\Software\SimonTatham
完成。
【讨论】:
cmd.exe,需要提升提示:仅会话:
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
仅会话:
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
reg import putty-sessions.reg
reg import putty.reg
注意:请勿将SimonTatham替换为您的用户名。
注意:它会在当前用户的桌面上创建一个reg文件。
注意:它不会导出相关的 SSH 密钥。
【讨论】:
HKEY_CURRENT_USER\... 导出时不需要提升命令提示符。只有HKEY_LOCAL_MACHINE、HKEY_CLASSES_ROOT等需要提升权限。
m0nhawk 的答案在 Windows 10 上对我不起作用 - 它需要提升命令提示符并拒绝发出文件。
这很有效,不需要提升:
reg export HKEY_CURRENT_USER\Software\SimonTatham\PuTTY putty.reg
【讨论】:
示例:
如何将腻子配置和会话配置从一个用户帐户转移到另一个用户帐户,例如创建新帐户并希望使用旧帐户中的腻子会话/配置时
流程:
- 将旧帐户中的注册表项导出到文件中
- 将注册表项从文件导入新帐户
导出注册密钥: (来自旧帐户)
导入 reg 密钥: (进入新帐户)
登录新帐户,例如汤姆
打开正常的“命令提示符”(不是管理员!)
键入“regedit”
从菜单中选择“导入”
选择要导入的注册表文件,例如'puttyconfig.reg'
完成
注意:
不要使用“管理员命令提示符”,因为设置位于“[HKEY_CURRENT_USER...]”下,并且 regedit 将以管理员身份运行并为管理员用户显示该部分,而不是让用户从中传输和/或传输到该部分。
【讨论】:
导入注册表导出比上面提到的要容易得多。 + 简单地说:
在 Win 7 Pro 上像冠军一样工作。
【讨论】:
我使用putty connection manager 创建会话数据库。将该数据库复制并导入到其他计算机很容易。
看到这个handy guide
【讨论】:
对于那些需要从离线注册表文件导入 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 后,一切都在那里。简单高效。
【讨论】:
使用此方法还可以执行批量配置更改,例如更改所有会话字体。
摘自此处:http://www.sysadmit.com/2015/11/putty-exportar-configuracion.html
【讨论】:
对于那些不想弄乱注册表的人,我们创建了一种保存到文件的 putty 变体。它位于这里:http://jakub.kotrla.net/putty/
如果 putty 团队将其作为一个选项纳入主发行版,那就太好了。
【讨论】:
@m0nhawk 发布的答案在我在 Windows 7 机器上测试时似乎不起作用。 相反,使用以下脚本将导出/导入 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
【讨论】:
如果您想在PuTTY Portable 上导入设置,您可以使用putty.reg 文件。
把它放到这条路径[path_to_Your_portable_apps]PuTTYPortable\Data\settings\putty.reg。程序将导入它
【讨论】:
当我尝试其他解决方案时,我得到了这个错误:
Registry editing has been disabled by your administrator.
我说,这太糟糕了!
我整理了以下用于导出和导入 PuTTY 设置的 powershell 脚本。导出的文件是windows .reg文件,如果你有权限会干净导入,否则使用import.ps1加载。
警告:像这样搞乱注册表是个坏主意™,我真的不知道自己在做什么。使用以下脚本需要您自担风险,并准备好让您的 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 不是很熟悉。欢迎改进!
【讨论】:
改进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"
【讨论】: