致命:使用cron作业推送到git时无法读取用户名 [英] fatal: could not read Username When pushing to git using a cron job

查看:94
本文介绍了致命:使用cron作业推送到git时无法读取用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我试图在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:

  1. 获取用户的SSH密钥(或生成一个:ssh-keygen -t rsa -b 4096 -C "your_email@example.com")
  2. 复制公钥(cat ~/.ssh/id_rsa.pub)的内容
  3. 转到github.com上的项目
  4. 转到项目设置
  5. 选择Deploy Keys( https://github.com/user/project/settings/键)
  6. 选择添加部署密钥
  7. 添加您的公钥内容
  8. 检查Allow write access
  9. 选择Add Key
  1. get the SSH key of the user(or generate one: ssh-keygen -t rsa -b 4096 -C "your_email@example.com")
  2. copy contents of the public key (cat ~/.ssh/id_rsa.pub)
  3. Go to the project on github.com
  4. Go to project settings
  5. Choose Deploy Keys (https://github.com/user/project/settings/keys)
  6. Choose add deploy key
  7. Add your public key contents
  8. Check Allow write access
  9. 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:

  1. 转到服务器上的存储库文件夹
  2. 运行git remote remove origin
  3. 运行git remote add origin git@github.user/project.git
  1. go to the repository folder on the server
  2. run git remote remove origin
  3. run git remote add origin git@github.user/project.git

这篇关于致命:使用cron作业推送到git时无法读取用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆