我正在制作一个自动克隆git存储库的批处理文件。 我将以下行放入批处理文件
git clone ssh://user@address/path
但它的执行打击了我:
[exec] Permission denied, please try again.
[exec] Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
[exec] fatal: Could not read from remote repository.
因为需要输入密码。 我尝试将命令更改为
git clone ssh://user:password@address/path
但它仍然要求我输入密码
有什么建议吗?
答案 0 :(得分:1)
处理此问题的最佳方法是建立公钥,这样您根本不需要密码。它也恰好更安全。例如,创建一个新的ssh密钥对:
$ ssh-keygen -t rsa -f ~/.ssh/git_key -C "steve@example.com"
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/sowens/.ssh/git_key.
Your public key has been saved in /Users/sowens/.ssh/git_key.pub.
The key fingerprint is:
SHA256:BxqMCuLKKa47IEzmAk7yRpv7MHuIwn9YWp5zlMs0O9A steve@example.com
The key's randomart image is:
+---[RSA 2048]----+
| |
| o |
|o . o . |
|==.. o . |
|X+.o o S . |
|*+* + E . |
|B=oo* * + |
|*.o*.= * |
|=+o+o o . |
+----[SHA256]-----+
然后将新的git_key.pub文件添加到您的github帐户:
https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
该文件将是一个文本文件,如下所示:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDjk8Ae7kGBhBM/hAhxe4BpjU1HIymRel6TWGJ3E17lki9qJroNjXpqxtsd27C2QSgdEvYEbX6Qv1jeTejpDqTnPdWvjnOWnk5zAo7IhKdKqzCMkBblmHR4LoJs/CeTuNG2vyTx7hb93nBPjni2EV05jW/vkoMoZbMV/4lO1A4oX5L52h5/hGDahfOLxjoU3wfkEssQkDo83GHzk5A5O6kSb6Lv9TFdaWCMqI0ZXOj3CuH3CSCIpoqS1Kibceu3kLHLN8KQZEXQmMrBEkJ69RfugfNtTddOO3gjhVmCAAUzZsRuxGQMDgmT0tnpQaJ0DdSxFwpEFSceR0/06Zykq+dl steve@example.com
答案 1 :(得分:0)
您可以使用sshpass
工具为git
提供密码:
sshpass -p password git clone ssh://user@address/path
但请注意,这不是安全方面的,使用密钥是更好的选择。