cron git push with ssh key

后端 未结 2 1036
轻奢々
轻奢々 2020-12-29 15:50

I setup a ssh key for github account, so I don\'t have to enter the password every time, it works fine. Here is the script I use:

#!/bin/bash
git push origin         


        
2条回答
  •  天命终不由人
    2020-12-29 16:39

    Based on your comments, I don't really understand why your script wouldn't work in cron. We can try a few things to clear things up.

    Add a configuration in ~/.ssh/config for the user running the cron job like this:

    Host github-project1
    User git
    HostName github.com
    IdentityFile /path/to/github.project1.key
    #or like this:
    #IdentityFile ~/.ssh/github.project1.key
    

    Then in your git working tree add a new remote like this:

    git remote add github-project1 github-project1:USER/PROJECT.git
    

    In the url there, github-project1:user/project.git, change only USER and PROJECT to the right values for your project, but leave github-project1 as is: it must match the value of the Host setting in the ssh configuration we just added.

    Finally, change the script to use this new remote:

    #!/bin/bash
    git push github-project1 master
    

    Test the script first in the shell, and then in cron.

提交回复
热议问题