automate ssh-keygen for github in powershell

≡放荡痞女 提交于 2019-12-11 02:49:05

问题


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 = "some.user@github.com"
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.


回答1:


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 """".



来源:https://stackoverflow.com/questions/18669766/automate-ssh-keygen-for-github-in-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!