致命:使用cron作业推送到git时无法读取用户名 [英] fatal: could not read Username When pushing to git using a cron job
问题描述
嘿,我试图在Mac上使用cron作业将代码推送到git.我使用crontab -e
编辑crontab,并在其中包含以下内容:
Hey I am trying to push code to git using a cron job on the Mac. I edit my crontab using crontab -e
and have the following inside:
* 12 * * 1 ~/Dropbox/MD/sync.sh
* 12 * * 5 ~/Dropbox/MD/sync.sh
脚本如下:
#!/bin/bash
cd ~/Dropbox/MD
/usr/bin/git add .
/usr/bin/git commit -m "Docs auto update"
/usr/bin/git push origin master
但是该命令失败,当我运行mail
时,我可以检查错误消息:fatal: could not read Username for 'https://github.com': Device not configured
.如何解决此问题?如果我从终端手动运行命令,则不会出现任何问题,也不会提示我输入用户凭据.
However the command fails and when I run mail
I can check the error message which is: fatal: could not read Username for 'https://github.com': Device not configured
. How can I fix this issue? If I run the commands manually from the terminal I have no issues and I am not prompted for user credentials.
对此,任何指针将不胜感激.谢谢!
Any pointers on this would be much appreciated. Thanks!
推荐答案
建议使用SSH密钥自动执行git任务时.您可以按照以下步骤设置具有推送访问权限的SSH密钥:
When automating git tasks using SSH keys is recommended. You can setup SSH keys with push access by following these steps:
- 获取用户的SSH密钥(或生成一个:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
) - 复制公钥(
cat ~/.ssh/id_rsa.pub
)的内容 - 转到github.com上的项目
- 转到项目设置
- 选择
Deploy Keys
( https://github.com/user/project/settings/键) - 选择添加部署密钥
- 添加您的公钥内容
- 检查
Allow write access
- 选择
Add Key
- get the SSH key of the user(or generate one:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
) - copy contents of the public key (
cat ~/.ssh/id_rsa.pub
) - Go to the project on github.com
- Go to project settings
- Choose
Deploy Keys
(https://github.com/user/project/settings/keys) - Choose add deploy key
- Add your public key contents
- Check
Allow write access
- Choose
Add Key
请注意,这仅适用于使用以下遥控器克隆的存储库:git@github.com:user/project.git
Please note this will only work for repositories cloned with the following remote: git@github.com:user/project.git
可以通过以下步骤更新遥控器:
The remote can be updated wit the following steps:
- 转到服务器上的存储库文件夹
- 运行
git remote remove origin
- 运行
git remote add origin git@github.user/project.git
- go to the repository folder on the server
- run
git remote remove origin
- run
git remote add origin git@github.user/project.git
这篇关于致命:使用cron作业推送到git时无法读取用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!