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. centos6.5下的mysql5.6.30安装

    1.解压mysql tar -xf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz  -C /usr/local mv mysql-5.6.30-linux-gli ...

  2. Tomcat部署web应用的方式

    对Tomcat部署web应用的方式总结,常见的有以下四种: 1.[使用控制台部署] 访问Http://localhost:8080,并通过Tomcat Manager登录,进入部署界面即可. 2.[利 ...

  3. 惠普M1005打印机无法自动进纸的问题

    惠普M1005打印机无法自动进纸的问题 问题起因 其实我也不太清楚是什么起因,前一天用的好好的惠普M1005打印机,在打印时没有直接打印,会弹出一个提示对话框,同时打印机显示屏上显示“load tra ...

  4. IOS_问题: Xcode8 安装KSImageName插件, 编代码就崩了

    Xcode 8之后, KSImageName插件就不能用了,如果安装了,就会导致一写英文代码Xcode 就崩了. 解决方法: 把这个插件删除,重启了一下xcode就可以了, 如果重启没用, 可以尝试下 ...

  5. php foreach 操作数组的代码

    php foreach 操作数组的代码.   foreach()有两种用法:  foreach(array_name as $value)  {  statement;  }  这里的array_na ...

  6. 重拾C,一天一点点_6

    break与continuecontinue只能用于循环语句goto最常见的用法是终止程序在某些深度嵌套的结构中的处理过程,例如一次跳出两层或多层循环.break只能从最内层循环退出到上一级的循环. ...

  7. svn 清空

    SVN是目前用得比较多的而且很方便的版本管理体系. 在开发过程中遇到了这样的问题: 有时我们需要一个干净的code版本,没有 .svn 这些文件夹记录的版本传到服务器上使用. 这个时候自己一个个去删除 ...

  8. 利用Jmeter做接口测试

    本文作者:大道测试团队-孙云 1.在安装jmeter之前先配置好JDK,再配置jmeter环境变量. 2.启动jmeter 启动jmeter: 双击Jmeter解压路径(apache-jmeter-3 ...

  9. (二)使用log4net写入数据库自定义日志

    1.配置项目环境 1.1 本文只显示需要修改配置的操作,初次引入log4net环境的请参考上文. 1.2 安装mysql-connector-net.msi环境,下载地址.并手动生成数据库日志信息表. ...

  10. 含有自增序列的表中使用truncate与delete的不同结果

    一个含有自增序列的表,使用delete跟truncate之后会有什么不同结果呢? 大概说一下,使用truncate,表中的记录全部被清除,如果向表中插入数据,那么数据的排序是从1开始的. 如果使用的是 ...