Is there a way to do this?
Or I have to take manually every record from Registry?
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)
Import reg key: (into NEW account)
Login into NEW account e.g. tom
Open normal 'command prompt' (NOT admin !)
Type 'regedit'
Select 'Import' from the menu
Select the registry file to import e.g. 'puttyconfig.reg'
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.
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 }
}
}
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