Linux – How to git pull without asking password

bashgitlinuxpasswordsssh

I have a problem for make a auto pull for a git repository. I explain my situation : i have 2 sever on linux (Debian), one for the repos (dev01) and another one for make documentation with doxygen (dev02). I make a script in bash to run doxygen every day and it's work fine.

The next step is to make some git pull on dev02 every day to pull repos on dev01. I try to make a script but when i make a git pull on dev02, it always ask me for dev01 password like this :

root@dev02:/repos# git pull
git@dev01's password:

I search for a solution on net and found something (expect) to make a script :

#!/usr/bin/env expect
cd /repos/repos_name
set password "git_password"
spawn /usr/bin/git pull
expect "git@dev01's password:"
send "$password\r"

It runs but do nothing… I found some solutions on web but all i try doesn't works. Maybe with Linux i can do other thing's to resolve it but I just begin on this OS.

How can i resolve this problem ?

Thanks

Best Answer

From the git@dev01, I'm guessing that you are pulling over SSH. Therefore you can use the same methods as for general passwordless SSH – specifically, public-key authentication. How to set it up has been described in great detail across many websites and tutorials, but here's the short summary:

  1. On the client, create a keypair using ssh-agent or PuTTYgen.

    (In this case, root@dev02 is the client, and git@dev01 is the server.)

  2. Copy the public key to the server, into the ~/.ssh/authorized_keys file.

    (Copy it from the ~/.ssh/id_rsa.pub file, or the "OpenSSH Public Key" text from PuTTYgen.)

  3. Run ssh -v user@server and make sure it shows the key being used:

    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Next authentication method: publickey
    debug1: Offering RSA public key: /home/grawity/.ssh/id_global
    debug1: Server accepts key: pkalg ssh-rsa blen 535
    debug1: Authentication succeeded (publickey).
    
Related Question