git - 为什么我可以从命令行克隆而不是 bash 脚本?

标签 git bash github

我想将一个开放的公共(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/

相关文章:

git - JGitFlow maven 插件不会将发布分支推送到远程

git - 致命的 : protocol error: bad line length character: <htm

git - 反转 git fetch

bash - sed 命令 - 适用于文件夹的所有文本 (.txt) 文件

bash - zsh 中的 IFS 行为与 bash 不同

git - 从 git 历史记录中删除文件不起作用

git - 无法使用sourcetree推送子树

linux - 并行执行命令的动态数量

windows - 由于 "SSL protocol"错误,Windows 上的 Git 无法使用远程

git - 如何删除github上的最新提交