automate ssh-keygen for github in powershell
Asked Answered
C

1

5

Is there a way to automate the ssh-keygen method in powershell? I'm trying to do it with the following code, but it requires the user to enter a password.

# Create your GitHub SSH Key
$MyEmailAddress = "[email protected]"
if (! (Test-Path  ("~/.ssh/id_rsa_test"))){

    ssh-keygen -t rsa -C "$MyEmailAddress" -f "id_rsa_test"

}

I tried entering the password switch, but then it complains that the password is null.

# either
ssh-keygen -t rsa -C "$MyEmailAddress" -f "id_rsa_test" -N ""

# or 
ssh-keygen -t rsa -C "$MyEmailAddress" -f "id_rsa_test" -N "$null"

I don't want a password in my key.

PS: I'm using poshgit which depends on mysysgit.

Cullet answered 7/9, 2013 at 4:39 Comment(6)
Please note, the answer here (https://mcmap.net/q/141990/-automate-ssh-keygen-t-rsa-so-it-does-not-ask-for-a-passphrase) isn't valid since -N '' throws a validation error on Windows because -N is null.Cullet
the further I dig, the more I'm thinking has to do with mysysgit throwing a null validation error when maybe it shouldn't. I've posted an "issue" github.com/msysgit/msysgit/issues/132Cullet
Maybe a I am little off-base, but it does seem a bit important in the creation of a cert that you do use a password - Yes I know and understand each Organization/Business requirements are different. However, when you state that you want to remove the password from the input screen, this could trigger an audit. Just my couple thoughts here. KentHarr
Why do you even want to automate ssh-keygen? What problem are you trying to solve?Phototherapy
@Cupcake I'm wiring up a Boxstarter script to automate the deployment and configuration of a Dev computer within a Virtual Machine. When connecting to github, it's a pain to have to enter a password for every push. There are many who just ENTER through the [Type a passphrase] section. help.github.com/articles/generating-ssh-keysCullet
The passphrase for github is not required for my personal repos. My computer has a passphrase, and the VM that this is being deployed on has another passphrase. I'm not worried about anyone committing malitious code to my github repos from my VM.Cullet
A
12

PowerShell seems to remove the empty double quotes and probably requires to escape them. Using """" instead of "" seems to work. Also, I believe one should use -P (passphrase) instead of -N (new passphrase in case you change it). So the final command line would be

ssh-keygen -t rsa -C "$MyEmailAddress" -f "id_rsa_test" -P """"
Ahn answered 7/9, 2013 at 19:52 Comment(4)
Same problem C:\Users\Chase> ssh-keygen -t rsa -C "[email protected]" -f "id_rsa_test" -P "" ssh-keygen.exe": option requires an argument -- PCullet
PowerShell seems to remove the empty double quotes and probably requires to escape them. Using -P """" seems to work.Ahn
Putting this into a Start-Process cmdlet worked the best for me: Start-Process ssh-keygen -ArgumentList '-t rsa -b 4096 -P """" -C "[email protected]" -f "id_rsa"' -WaitFrigate
You could just define it as a variable??? Come on guys: $password = '""'.... -P $passwordDido

© 2022 - 2024 — McMap. All rights reserved.