Batch file 如何在批处理文件中运行git clone命令时提供密码
我正在制作一个自动克隆git存储库的批处理文件。 我在批处理文件中添加了以下行Batch file 如何在批处理文件中运行git clone命令时提供密码,batch-file,ssh,git-clone,Batch File,Ssh,Git Clone,我正在制作一个自动克隆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 rep
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
但它仍然在问我密码
有什么建议吗?处理这个问题的最好方法是建立一个公钥,这样你就不需要密码了。它也恰好更安全。例如,创建新的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帐户:
该文件将是如下所示的文本文件:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDjk8Ae7kGBhBM/hAhxe4BpjU1HIymRel6TWGJ3E17lki9qJroNjXpqxtsd27C2QSgdEvYEbX6Qv1jeTejpDqTnPdWvjnOWnk5zAo7IhKdKqzCMkBblmHR4LoJs/CeTuNG2vyTx7hb93nBPjni2EV05jW/vkoMoZbMV/4lO1A4oX5L52h5/hGDahfOLxjoU3wfkEssQkDo83GHzk5A5O6kSb6Lv9TFdaWCMqI0ZXOj3CuH3CSCIpoqS1Kibceu3kLHLN8KQZEXQmMrBEkJ69RfugfNtTddOO3gjhVmCAAUzZsRuxGQMDgmT0tnpQaJ0DdSxFwpEFSceR0/06Zykq+dl steve@example.com
您可以使用
sshpass
工具为git
提供密码:
sshpass -p password git clone ssh://user@address/path
但请注意,它不具有安全性,使用密钥是更好的选择。它不是github存储库,它是一个我没有完全访问权限的私有存储库。与repo管理员联系是有意义的。私有存储库是否公开了github用户界面,还是完全是命令行?不是,请下次阅读问题以证实。在那篇文章中提供的解决方案,在这篇文章中作为一种尝试被通知。这就是为什么投票是赞成的。对不起,我在里面看到了一些ssh的东西。