我想在PowerShell中加密密码,并将其与plink
和putty
一起使用。
是的,我知道它只需要明文密码(Password encryption using SecureString for plink.exe command)。
不,我不会使用生成的密钥,因为我们不支持它。
我的问题:
putty
或plink
中为putty
标志使用加密密码-i
而不是-pw
。我的securePass.ps1
代码:
$password = read-host -prompt "Enter your Password"
write-host "$password is password"
$secure = ConvertTo-SecureString $password -force -asPlainText
$bytes = ConvertFrom-SecureString $secure
$bytes | out-file C:\encrypted_password1.txt
主要是:
$securePass = Get-Content C:\encrypted_password1.txt
$pass = $securePass | ConvertTo-SecureString
plink -batch -ssh $defUser@$srv -pw $pass
putty -ssh $defUser@$srv -pw $pass
发布于 2017-11-02 07:44:11
如您所知,您不能对PuTTY/Plink使用加密密码(SecureString
)。
您所能做的就是解密安全字符串,并将解密后的纯文本密码传递给PuTTY/Plink。
有关解密,请参见PowerShell - Decode System.Security.SecureString to readable password。
$securePass = Get-Content C:\encrypted_password1.txt
$pass = $securePass | ConvertTo-SecureString
$Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($pass)
$decrypted = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)
[System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($Ptr)
plink -batch -ssh $defUser@$srv -pw $decrypted
PuTTY 0.77 Plink新支持 switch,它允许更安全地通过本地文本文件传递密码(同时仍然是纯文本)。
你的问题2)没有任何意义。你写的你不能用钥匙。所以您不能使用-i
交换机。更别提使用一些“生成的密码”了。
https://stackoverflow.com/questions/47069785
复制相似问题