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.

6
  • Please note, the answer here (stackoverflow.com/a/14946700/124069) isn't valid since -N '' throws a validation error on Windows because -N is null. Commented Sep 7, 2013 at 4:57
  • 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/132 Commented Sep 7, 2013 at 5:13
  • 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. Kent Commented Sep 7, 2013 at 6:03
  • 1
    Why do you even want to automate ssh-keygen? What problem are you trying to solve? Commented Sep 7, 2013 at 6:47
  • @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-keys Commented Sep 7, 2013 at 15:04

1 Answer 1

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 """"
Sign up to request clarification or add additional context in comments.

4 Comments

Same problem C:\Users\Chase> ssh-keygen -t rsa -C "[email protected]" -f "id_rsa_test" -P "" ssh-keygen.exe": option requires an argument -- P
PowerShell seems to remove the empty double quotes and probably requires to escape them. Using -P """" seems to work.
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"' -Wait
You could just define it as a variable??? Come on guys: $password = '""'.... -P $password

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.