有没有办法做到这一点?
或者我必须从注册表中手动获取每条记录?
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
, require elevated command prompt:regedit /i putty-sessions.reg
regedit /i putty.reg
reg import putty-sessions.reg
reg import putty.reg
注意:请勿将SimonTatham
替换为您的用户名。
注意:它将在当前用户的桌面上创建一个reg
文件。
注意:它不会导出相关的SSH密钥。
@ 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
m0nhawk的回答在Windows 10上对我不起作用 - 它需要提升命令提示符并拒绝发出文件。
这有效,不需要提升:
reg export HKEY_CURRENT_USER\Software\SimonTatham\PuTTY putty.reg
使用此方法还可以执行批量配置更改,例如更改所有会话字体。
从这里提取:http://www.sysadmit.com/2015/11/putty-exportar-configuracion.html
我使用putty connection manager创建会话数据库。将数据库复制并导入其他计算机很容易。
看到这个handy guide
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 }
}
}
当我尝试其他解决方案时,我收到此错误:
Registry editing has been disabled by your administrator.
Phooey,我说!
我将以下powershell脚本放在一起,用于导出和导入PuTTY设置。导出的文件是一个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不是很熟悉。欢迎改进!
完成。
如果要在PuTTY Portable
上导入设置,可以使用putty.reg
文件。
只是把它放到这条路上[path_to_Your_portable_apps]PuTTYPortable\Data\settings\putty.reg
。程序将导入它
对于那些需要从离线注册表文件导入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后,一切都在那里。简单高效。
导入注册表导出比上面说的容易得多。 +简单地说:
在Win 7 Pro上像冠军一样工作。
对于那些不想弄乱注册表的人,已经创建了一个保存到文件的putty变体。它位于这里:http://jakub.kotrla.net/putty/
如果腻子团队将其作为主要发行版的一个选项,那将是很好的。
对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"
例: 如何将putty配置和会话配置从一个用户帐户转移到另一个用户帐户,例如创建新帐户时,想要使用旧帐户中的putty会话/配置
处理: - 将旧帐户的注册表项导出到文件中 - 将注册表项从文件导入新帐户
导出注册码:(来自OLD账户)
导入注册码:(进入新帐户)
注意: 不要使用'admin命令提示符',因为设置位于'[HKEY_CURRENT_USER ...]'下,regedit将以admin身份运行,并显示admin-user的部分,而不是用户从和/或转移到。