我想将一个开放的公共(public)存储库克隆到另一个目录中。要从命令行执行此操作,我键入:
git clone git@github.com:computersarecool/dotfiles.git documents/gitprojects/dotfiles
有效。
但是,现在我想通过 bash
脚本来完成。在脚本中我有完全相同的代码:
#!/bin/bash
git clone git@github.com:computersarecool/dotfiles.git documents/gitprojects/dotfiles
但现在我得到一个错误:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
谁能给我解释一下这个问题?我什至不明白为什么它在 repo 开放时首先要求提供公钥。
最佳答案
如果它确实是一个公开的开放 repo,请使用 https 而不是 ssh:
#!/bin/bash
git clone https://github.com/computersarecool/dotfiles.git documents/gitprojects/dotfiles
如果你想坚持使用 ssh,你应该让 ssh-agent 知道你的 id_rsa key :
#!/bin/bash
eval `ssh-agent -s`
ssh-add /home/<Your username>/.ssh/id_rsa
git clone git@github.com:computersarecool/dotfiles.git documents/gitprojects/dotfiles
添加您的用户名(并检查 ~/.ssh 目录的内容以验证您的私钥名为 id_rsa)
关于git - 为什么我可以从命令行克隆而不是 bash 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38706797/