Q:  http://stackoverflow.com/questions/7994663/git-push-via-cron

   I'm trying to run a git push from cron. When I do the command interactively on the shell it's going through fine. When running the command from my user's crontab, cron delivers the error message

Permission denied (publickey).

I presume it hasn't to do with finding or reading my ~/.ssh/id_rsa, as I can cat the file from cron alright. UID and EUID are set fine in the cron job. - Any ideas?

UPDATE

I got it working when supplying the environment key SSH_AUTH_SOCK to my cron job, but I'm concerned that this is only valid as long as I'm logged in. I'm looking for a solution that works independent of interactive logins.

A:

down vote accepted

As explained here,it can be due to the lack of knowledge from the cron session shell of the ssh agent.
If that is the case (ie if you are using private ssh keys with a passphrase), keychain is the usual solution (as mentioned here).
More details in this example: "Passwordless connections via OpenSSH using public key authentication, keychain and AgentForward".

Very brief synopsis

1. Generate private/public key pair (id_dsa and id_dsa.pub).

Save private key in ~/.ssh/id_dsa on trusted hosts you will ssh from.

Append public key to ~/.ssh/authorized_keys on hosts you will ssh to.

Do not use ~/.ssh/authorized_keys2.  If you see that file, remove it

and upgrade to a recent version of SSH.

2. Set ForwardAgent yes in ssh_config on all hosts you ssh

from.  Set PubkeyAuthentication yes in sshd_config on all

hosts you ssh to.  Maybe set StrictModes no in sshd_config.

3. Install keychain then configure by adding the following lines

to your $HOME/.bash_profile:

/usr/local/bin/keychain $HOME/.ssh/id_dsa

source $HOME/.keychain/${HOSTNAME}-sh

4. For crontab scripts that use ssh, add the following line in

order to avoid having to manually enter a passphrase:

source $HOME/.keychain/${HOSTNAME}-sh

5. ssh from host to host without needing to enter passwords.  Where

you can ssh, you can also scp, sftp, etc., all securely but without

having to enter your passwords on the various hosts you use.

crontab定时运行git命令 更新代码库的更多相关文章

  1. 换个视角来看git命令与代码库发生网络交互报错事件

    git的一系列命令中像 clone.pull.push等与代码库发生网络交互时,可能报下面的错误信息 fatal: remote error: CAPTCHA required Your Stash ...

  2. 15分钟学会使用Git和远程代码库

    git是个了不起但却复杂的源代码管理系统.它能支持复杂的任务,却因此经常被认为太过复杂而不适用于简单的日常工作.让我们诚实一记吧:Git是复杂的,我们不要装作它不是.但我仍然会试图教会你用(我的)基本 ...

  3. 使用Git和远程代码库

    git是个了不起但却复杂的源代码管理系统.它能支持复杂的任务,却因此经常被认为太过复杂而不适用于简单的日常工作.让我们诚实一记吧:Git是复杂的,我们不要装作它不是.但我仍然会试图教会你用(我的)基本 ...

  4. 【git】15分钟学会使用Git和远程代码库

    Git是个了不起但却复杂的源代码管理系统.它能支持复杂的任务,却因此经常被认为太过复杂而不适用于简单的日常工作.让我们诚实一记吧:Git是复杂的,我们不要装作它不是.但我仍然会试图教会你用(我的)基本 ...

  5. 15 分钟学会使用 Git 和远程代码库

    Git是个了不起但却复杂的源代码管理系统.它能支持复杂的任务,却因此经常被认为太过复杂而不适用于简单的日常工作.让我们诚实一记吧:Git是复杂的,我们不要装作它不是.但我仍然会试图教会你用(我的)基本 ...

  6. 基于git命令的代码统计方法

    基于git命令的代码统计方法 没什么好说的,基于git log命令,使用前提是安装了git ...... .统计所有人代码量 统计所有人代码增删量,拷贝如下命令,直接在git bash等终端,git项 ...

  7. Linux-Centos 用crontab定时运行python脚本详细步骤

    服务器总是要定时运行某个程序,而我在解决这个问题的时候遇到很多困难, 特此记录下来. 1.编辑crontab配置 crontab -e 服务器一般会安装好crontab,若没有安装请按命令安装 yum ...

  8. crontab 不能执行git命令问题备忘

    这问题够隐蔽,折腾了近两个小时. 命令 git checkout tagname 手工执行都正常 但在crontab运行时发现分支一直切不过去. 后来告诉是crontab默认的 path  设置和系统 ...

  9. 00008 - crontab定时执行任务命令详解

    linux 系统则是由 cron (crond) 这个系统服务来控制的.Linux 系统上面原本就有非常多的计划性工作,因此这个系统服务是默认启动的.另 外, 由于使用者自己也可以设置计划任务,所以, ...

随机推荐

  1. xmlspy注册后打开报错的解决办法

    XMLSpy 2011中文版破解补丁使用方法 1.如果你下载的版本是r2sp1的话(r2不用此步骤),先用补丁主程序(altova.xmlspy.v2011r2sp1b-patch.exe).2.XM ...

  2. Android studio 读取properties文件

    System.out.println(Thread.currentThread().getContextClassLoader().getResource("").getPath( ...

  3. 私人定制自己的linux小系统

     私人定制自己的linux小系统 一.前言    linux操作系统至1991.10.5号诞生以来,就源其开源性和自由性得到了很多技术大牛的青睐,每个linux爱好者都为其贡献了自己的一份力,不管是在 ...

  4. SharedPreferences的基本用法

    获取SharedPreferences的两种方式: 1 调用Context对象的getSharedPreferences()方法 2 调用Activity对象的getPreferences()方法 两 ...

  5. Nginx,LVS,HAProxy,负载均衡之选择

    Nginx的优点:性能好,可以负载超过1万的并发.功能多,除了负载均衡,还能作Web服务器,而且可以通过Geo模块来实现流量分配.社区活跃,第三方补丁和模块很多支持gzip proxy缺点:不支持se ...

  6. jquery插件formValidator的ajaxValidator传参数问题

    最近在用formValidator插件,遇到一个问题.当我想用ajaxValidator的url传参数时,$("#tbName").val().document.getElemen ...

  7. PHP中include和require绝对路径、相对路径问题

    在写PHP程序时,经常要用到include或require包含其他文件,但是各文件里包含的文件多了之后,就会产生路径问题. 如下目录: <web>(网站根目录) ├<A>文件夹 ...

  8. Android实现发短信与打电话的功能

    //发短信 class SendMsgClickListener implements OnClickListener { public void onClick(View v) { //调用Andr ...

  9. Response.Redirect和Server.Transfer

    今天又比较闲,逛了逛园子,看看asp.net的内容,看到一篇关于这两个的比较: http://www.cnblogs.com/yunfeng8967/archive/2008/03/06/109323 ...

  10. 如何重建Octopress本地环境

    # 安装rvm, ruby, bundler 略 # 克隆octopress $ git clone git://github.com/imathis/octopress.git octopress ...