I have a profile that gets executed every time I open my PowerShell window. Since I do some SSH'ing, I need to ensure that my gets added right after I start up PowerShell. But I want to avoid asking my passphrase for the SSH as long as it's already added to the ssh-agent. The solution to this problem is described here, but for the Linux shell.
I have converted the solution described there to a PowerShell equivalent, which is as follows:
$ssh_add = "$env:ProgramFiles/Git/usr/bin/ssh-add.exe"
$ssh_keygen = "$env:ProgramFiles/Git/usr/bin/ssh-keygen.exe"
$my_key_path = "$env:USERPROFILE/.ssh/id_rsa"
$my_ssh_key = & $ssh_keygen -lf $my_key_path
$ssh_keys = & $ssh_add -l
if (!(Select-String -Pattern $my_ssh_key -Path $ssh_keys -SimpleMatch -Quiet))
{
& $ssh_add -t 5h $my_key_path
}
The SSH keys happen to contain colons, which PowerShell seems to think are drive letters. This results in the following error message:
Select-String : Cannot find drive. A drive with the name '4096 SHA256' does not exist.
The SSH keys in the following form:
$my_ssh_key = 4096 SHA256:somelongSSHkey some.email@stackoverflow.com (RSA)
$ssh_keys = 4096 SHA256:anotherlongSSHkey /c/Users/MyUser/.ssh/id_rsa (RSA)
How can I prevent the colon from being parsed as a drive letter seperator?